13

The MWE below shows that the solution at How can I change the font family in pgfplots? does not cover all the cases. The digits in the plot itself and the subscript in math mode in the title need further attention.

enter image description here

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usepackage{pgfplotstable}

%deal with warning message in log
\pgfplotsset{compat=1.8}

\usepackage{helvet}
\usepackage[eulergreek]{sansmath}
\pgfplotsset{
  tick label style = {font=\sansmath\sffamily},
  every axis label = {font=\sansmath\sffamily},
  legend style = {font=\sansmath\sffamily},
  label style = {font=\sansmath\sffamily}
}

\pgfplotstableread[col sep=comma]{
name, footprint
Google search,  0.2
Movie download, 20
}\carbonfootprints

\begin{document}
\begin{tikzpicture}[font=\sffamily]

\begin{axis}[ 
      xbar, xmin=0,
      tick style={draw=none},
      width=8cm, height=3cm, 
      title={Estimated carbon footprint, g CO${}_2$}, 
      enlarge y limits=0.3,
      ytick=data,
      yticklabel style={align=right},
      yticklabels={
        2. Google search, 
        1. Movie download
      },
      nodes near coords,
      nodes near coords align={horizontal}, 
    ]
    \addplot [fill=red] table [x=footprint, y expr=\coordindex] 
             {\carbonfootprints};
\end{axis} 
\end{tikzpicture}
\end{document}
17

If you add font=\sffamily\sansmath to the tikzpicture options (or the axis options), all text will be in sans serif, without you having to find all relevant styles:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

%deal with warning message in log
\pgfplotsset{compat=1.8}

\usepackage{helvet}
\usepackage[eulergreek]{sansmath}

\pgfplotstableread[col sep=comma]{
name, footprint
Google search,  0.2
Movie download, 20
}\carbonfootprints

\begin{document}
\begin{tikzpicture}[font=\sffamily\sansmath]

\begin{axis}[ 
      xbar, xmin=0,
      tick style={draw=none},
      width=8cm, height=3cm, 
      title={Estimated carbon footprint, g CO${}_2$}, 
      enlarge y limits=0.3,
      ytick=data,
      yticklabel style={align=right},
      yticklabels={
        2. Google search, 
        1. Movie download
      },
      nodes near coords,
      nodes near coords align={horizontal}
    ]
    \addplot [fill=red] table [x=footprint, y expr=\coordindex] 
             {\carbonfootprints};
\end{axis} 
\end{tikzpicture}
\end{document}
  • 2
    You solved a problem of mine: Making Tikz Graphics with serif fonts for the report, and making them with sans-serif fonts as standalone image for presentations. Including the sansmath and \tikzset{every picture/.style={font=\sffamily\sansmath}} into the preamble of the standalone tex file did the trick without the need of changing the original tikz code for the image. – Dohn Joe Jan 25 '16 at 8:45
  • 1
    Same here. Including [font=\sffamily\sansmath] in the tikzpicture-options made the\pgfplotsset-definitions regarding sans-serif usage (axis and tick labels, legend) superfluous. Additionally, it solved the problem of displaying an additional node text in sans-serif font (which the pgfplotsset, in my case, did not). – pogo-otter Sep 13 '16 at 6:57

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.