3

I need to make figure with Garamond font applied to axes and labels, as well to text in nodes.

This is my MWE:

\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{fontspec}
\setmainfont{Garamond}

\begin{document}
\pgfplotsset{every axis/.append style={
line width=.5 pt,
tick style={line width=.6pt}}}
\begin{tikzpicture}
\begin{axis}[
clip mode=individual,
height=8cm,
width=10cm,
xmin=1.9,
ymin=0,
ymax=0.5,
enlarge x limits=.0,
enlarge y limits=.02,
ylabel={YLABEL},
xlabel={XLABEL},
minor x tick num=4,
minor y tick num=4,
tick label style={/pgf/number format/fixed},
every node near coord/.append style={font=\tiny},
]
\addplot[black,dashed] coordinates {(0,0) (3.4,.49)};
\addplot[black,dashed] coordinates {(0,0) (3.44,.44)};

\node[] at (axis cs: 2.7,0.2) {Text with Garamond font 1 2 3 4 5 6 7 8 9 0};

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

This is output:

enter image description here

The text in node is printed using Garamond font, but axes and labels did not change.

What is the simple way to solve this problem?

1 Answer 1

5

See two marked bits (otherwise the tic labels are set in math mode by default)

\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{fontspec}
\usepackage{ebgaramond}%<=== think you needed this - you presumably have the font locally otherwise

\begin{document}
\pgfplotsset{every axis/.append style={
line width=.5 pt,
tick style={line width=.6pt}}}
\begin{tikzpicture}
\begin{axis}[
clip mode=individual,
height=8cm,
width=10cm,
xmin=1.9,
ymin=0,
ymax=0.5,
enlarge x limits=.0,
enlarge y limits=.02,
ylabel={YLABEL},
xlabel={XLABEL},
minor x tick num=4,
minor y tick num=4,
tick label style={/pgf/number format/assume math mode=true},%<=== this is what you need
every node near coord/.append style={font=\tiny},
]
\addplot[black,dashed] coordinates {(0,0) (3.4,.49)};
\addplot[black,dashed] coordinates {(0,0) (3.44,.44)};

\node[] at (axis cs: 2.7,0.2) {Text with Garamond font 1 2 3 4 5 6 7 8 9 0};

\end{axis}
\end{tikzpicture}
\end{document}
1
  • This works great also for heat maps and their contour lines, but it seems it doesn't affect the labels of its colorbar, which is configured in the axis arguments together with tick label style.
    – Sim Son
    Commented Aug 24, 2023 at 18:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .