# PGF/TikZ and Sans Serif Fonts

I have a TikZ/PGF file created directly by a graphing package of the form \begin{tikzpicture}{dimensions} ... \end{tikzpicture}. The file uses \pgftext[...]{\selectfont{Some text here or \boldmath$math$}} to render text.

By default, when I include the file in my document, the text is typeset in the default font for my document (Latin Modern Serif). However, I wish for all of my figures/graphs to be typeset in a sans-serif font (Latin Modern Sans). How can I go about this?

Ideally, I would like to accomplish this without having to edit the file directly (so just changing the LaTeX around where I include it).

Update: Minimal Example

\begin{tikzpicture}
\pgftext{\selectfont{Hello \boldmath$W \times orld$}}
\end{tikzpicture}


Anything which can correctly set that piece of text to be sans-serif should do the trick.

-
Your graphing package should use \node with its font option instead of \pgftext (in a tikzpicture !) and \selectfont... – Paul Gaborit Nov 3 '14 at 22:40

There are two issues here. One is to make the default font sans-serif so that \selectfont selects it. The other is to get the math to use bold, sans-serif letters.

For the first, \renewcommand{\familydefault}{\sfdefault} works. See “How do you change the document font in LaTeX?” from StackOverflow.

For the second, any new math font versions set up are deselected by \boldmath. In fact, \boldmath expands to \mathversion{bold}. So we need to override the font selections for the bold math version to choose bold, sans-serif letters. This is accomplished by \SetSymbolFont{letters}{bold}{OML}{cmbr}{bx}{it} (There is no Latern Modern math alphabet; Computer Modern Bright is a suggested replacement).

Here is the complete working example. You just need to add two lines to the preamble, and nothing to the automatically-generated part.

\documentclass{article}
\usepackage{tikz}
\usepackage{lmodern}
\SetSymbolFont{letters}{bold}{OML}{cmbr}{bx}{it}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\begin{tikzpicture}
\pgftext{\selectfont{Hello \boldmath$W \times orld$}}
\end{tikzpicture}
\end{document}


-
Works a treat for regular text, but does not touch the math. However, I understand that sans-serif math is a problem in general. – Freddie Witherden Nov 5 '10 at 9:36
Oh, I didn't realize you wanted the math to change font. Different question. But the answer can be adapted...whatever commands you can find to do it once, add them before \sffamily. – Matthew Leingang Nov 5 '10 at 9:57
I've rewritten this answer to better address the user's updated question. – Matthew Leingang Nov 3 '14 at 15:26

Some more details could have been very helpful. To choose a certain font style for your picture you simply have to give appropriate options to the tikzpicture environment.

\begin{tikzpicture}[font=\sffamily]
% picture contents
\end{tikzpicture}


For a global setting you may try \tikzstyle{every picture}+=[font=\sffamily] in the preamble.

-
No luck; I've added a minimal example to my original question so as to be more specific. – Freddie Witherden Nov 3 '10 at 23:54
@Freddie: It's better if you include a minimal working example, i.e., a document that can be complied as is, and then say what doesn't work out as you want. – Hendrik Vogt Nov 4 '10 at 15:40