6

I have a pgfplots axis, displaying some data. The ticklabels are defined manually, so the standard font used is the base text font.

What I would like to do is to obtain tick labels using the math font of my document without putting all of my ticklabels in math mode using $ ... $.

Basically, I think I just need to add some ticklabel style={font=\mathseries} but I don't know what command to use instead of \mathseries.

I apologize in advance for this somewhat dummy question.

CLOSE EDIT

I used egreg's answer in the duplicate link, not the accepted answer.

Edit: I updated the MWE, removing mtpro2, which actually changes the output, but not the issue.

MWE

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{times}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}

\begin{axis}[%
width=5cm,
height=5cm,
at={(0cm,0cm)},
scale only axis,
plot box ratio=1 1 1,
xmin=0,
xmax=10,
xtick={0,2,4,6},
% HERE THE LABELS DEPEND ON THE MATH MODE
xticklabels={$0.12$,0.12,$0.345$,0.345},
ymin=-0.5,ymax=9.5,
ytick=\empty,
zmin=0.0000e+00,
zmax=10,
view={-4.4000e+01}{5.9600e+01},
axis x line*=bottom,
axis y line*=left,
axis z line*=left,
ticklabel style={font={\footnotesize}},
]

\end{axis}
\end{tikzpicture}%
\end{document}

Result without mtpro2 enter image description here

Result with mtpro2 enter image description here

As you can see, the labels within $ ... $ and the other labels have different fonts.

Edit 2 Comment regarding the use of assume math mode from pgfmanual v3.0.1a p954

/pgf/number format/assume math mode={hbooleani} (default true) Set this to true if you don’t want any checks for math mode. The initial setting checks whether math mode is active using \pgfutilensuremath for each final number. Use assume math mode=true if you know that math mode is active. In that case, the final number is typeset as-is, no further checking is performed.

Edit 3 I added a xticklabel={$\pgfmathprintnumber{\tick}$} after the xticklabels={...} call. I actually overwrites the manually defined xticklabels and uses the values in xtick but gives the desired math output...

Updated MWE

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{times}
\pgfplotsset{compat=newest}
\pgfplotsset{xticklabel={\pgfmathprintnumber[assume math mode=true]{\tick}}}
\begin{document}
\begin{tikzpicture}

\begin{axis}[%
width=5cm,
height=5cm,
at={(0cm,0cm)},
scale only axis,
plot box ratio=1 1 1,
xmin=0,
xmax=10,
xtick={0,2,4,6},
% HERE THE LABELS DEPEND ON THE MATH MODE
xticklabels={$0.12$,0.12,$0.345$,0.345},
%PRINTS THE TICKS IN MATH MODE BUT NOT THE MANUALLY SET TICKLABELS
xticklabel={$\pgfmathprintnumber{\tick}$},
ymin=-0.5,ymax=9.5,
ytick=\empty,
zmin=0.0000e+00,
zmax=10,
view={-4.4000e+01}{5.9600e+01},
axis x line*=bottom,
axis y line*=left,
axis z line*=left,
ticklabel style={font={\footnotesize}},
]
\end{axis}
\end{tikzpicture}%
\end{document}

enter image description here

BambOo
  • 8,801
  • 2
  • 20
  • 47
  • they are already in math mode. So if you don't do anything they should pickup the math font. – percusse Apr 17 '18 at 14:52
  • 1
    If I compile the document, I don't get the same result for xticklabels and yticklabels – BambOo Apr 17 '18 at 14:57
  • 1
    mtpro is not longer on ctan. The replacement, mtp2lite, isn't either, at least not directly. – John Kormylo Apr 17 '18 at 16:54
  • Yes, it is not available on CTAN. mtp2lite is freely available, but I will try to reproduce the error without it. – BambOo Apr 17 '18 at 19:15
  • @JohnKormylo, I removed mtpro2, but the problem remains. – BambOo Apr 17 '18 at 19:29
  • @percusse The MWE demonstrates that it is not the case here, maybe because of the package times? – anderstood Apr 17 '18 at 21:23
  • @anderstood I still can't see the obvious. What is the difference in this output? inline math characters are different and they are picked up as math font. – percusse Apr 17 '18 at 21:35
  • @percusse If you compare the fives (or the twos) in the bottom right of the picture, they obviously have different fonts. I think the OP would like to type labels such as {0.12, 3.45, ...} so that they are rendered as they had typed {$0.12$, $3.45$, ...}. – anderstood Apr 17 '18 at 23:00
  • @anderstood, that's exactly what I need ;) – BambOo Apr 18 '18 at 07:45
  • I don't know why \pgfplotsset{xticklabel={\pgfmathprintnumber[assume math mode=false]{\tick}}} does not work (see 373722). – anderstood Apr 18 '18 at 13:01
  • @anderstood Doing assume math mode=true only seems to leave the result as it is no matter what the value contains. See the edit in the question. However, there is no explanation on what assume math mode=false should do. Only check for math environment ? enforce math environment ? – BambOo Apr 18 '18 at 14:02
  • If you add a math font, it seems to work fine. For example try \usepackage{mathptmx}. See also this answer. If you're using mtpro2 I don't know what the problem is, but the difference might be unnoticeable... – anderstood Apr 18 '18 at 18:27
  • 1
    @anderstood, I just edited the post to show the result with mtpro2 – BambOo Apr 18 '18 at 18:56
  • 1
    This question is similar: https://tex.stackexchange.com/q/281503/159527 and its accepted answer should do what you want. The third method looks especially suitable. – RobotRaven Nov 13 '18 at 18:14
  • @RobotRaven, thanks ! It took me a long time searching for an answer before asking this one, but I guess it is relying a lot on how the question is aked. Actually, the accepted answer does not seem to work for me, and egreg's answer feels like the right one to me. – BambOo Nov 14 '18 at 08:45

0 Answers0