TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

 \pgftext{\selectfont{Hello \boldmath$W \times orld$}}

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

share|improve this question
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
up vote 1 down vote accepted

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.


 \pgftext{\selectfont{Hello \boldmath$W \times orld$}}

sample code output

share|improve this answer
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.

% picture contents

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

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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