I would like to use the same font that I'm using in the whole document (Gentium Plus) for any text in figures (at the moment I only have tikz-figures) in the document. So far the standard font is used there.
A minimal example that I'm compiling with xetex (I took the picture from texample.net and simplified it a bit):
\documentclass{scrbook}
\usepackage{fontspec}
\setmainfont[Renderer=ICU,Mapping=tex-text]{Gentium Plus}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
xlabel=$Example label$,
ylabel=$Example label$]
\addplot plot coordinates {
(0,2)
(2,3)
(3,1)
};
\addlegendentry{Example text}
\end{axis}
\end{tikzpicture}
\end{figure}
This is some example text in Gentium Plus. Looks quite cool, doesn't it?
\end{document}
I only found answers on how to use sans serif fonts in tikz pictures, but none seemed to asked my question before, although I think it should be easy to do.
Best Answer
You haven't set up a mathematics font, so LaTeX will use the default Computer Modern for mathematics.
By wrapping your label text in dollar signs (
$
), you are asking LaTeX to typeset them as mathematics, so Computer Modern Italic (with large letter spacing to indicate multiplication of variables) is used.Solution for axis labels only
Removing the dollar signs from around your labels prints them in Gentium as desired. Also,
\usepackage{tikz}
is not needed sincepgfplots
loadstikz
on its own. You might consider specifying a version forpgfplots
(using\pgfplotsset{compat=<version>}
) to obtain better label spacing and ensure future compatibility.Note that the tick labels are still typeset in Computer Modern. This is because
pgfplots
uses math mode for these elements. Read on if you'd like to fix this...;-)
Solution for axis labels and tick labels
Adding
\pgfplotsset{/pgf/number format/assume math mode=true}
to the preamble will causepgfplots
to use text mode for the tick labels:Solution for mathematics font setup
If you don't have mathematics in your document, or don't care about the discrepancy highlighted above, you may skip this part.
The best results are obtained when using a font with true maths support, but the
mathspec
package (used in place offontspec
) allows one to "fake" a maths font using a given text font. Please understand that results will be much better with a true math font, but this solution is acceptable if you have only basic mathematics in the document: