1

I learned from this answer that the package sansmath can be used to change the font of tick label by setting option tick label style. Now I want to set the tick label font to be sans serif font while other fonts such as legend font and label font are still serif fonts. I use xelatex and unicode-math. How can I achieve this?

\documentclass{article}
\usepackage{sansmath}
\usepackage{pgfplots}
\pgfplotsset{
    compat=1.16,
    tick label style={font=\sansmath\sffamily},
}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Termes Math}
\begin{document}
\begin{tikzpicture}
    \begin{axis}
        \addplot coordinates {(1,2) (2,3)};
        \addlegendentry{$n=1$};
    \end{axis}
\end{tikzpicture}
\end{document}

In the above example, the tick label font is in the italic form. I want to make only the tick label font is sans serif and all other positions are still serif fonts.

0

I do not know if I am on the right track, and will be happy to delete this. I also do not have \setmathfont{TeX Gyre Termes Math} installed, but hope this is not too relevant. I am wondering if you are looking for

\documentclass{article}

\usepackage{sansmath}
\usepackage{pgfplots}
\pgfplotsset{
    compat=1.16,
    xticklabel={\begin{sansmath}$\pgfmathprintnumber{\tick}$\end{sansmath}},
    yticklabel={\begin{sansmath}$\pgfmathprintnumber{\tick}$\end{sansmath}},
}
\usepackage{unicode-math}
%\setmathfont{TeX Gyre Termes Math}
\begin{document}
\begin{tikzpicture}
    \begin{axis}
        \addplot coordinates {(1,2) (2,3)};
        \addlegendentry{$n=1$};
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • Thanks for your answer. Can I make the tick label font to be the upright? – Ice0cean May 30 at 11:42
  • @Ice0cean E.g. with xticklabel={\sffamily\pgfmathprintnumber{\tick}}, yticklabel={\sffamily\pgfmathprintnumber{\tick}},. – user121799 May 30 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.