更改 pgfplots 中的字体系列(后续)

更改 pgfplots 中的字体系列(后续)

下面的 MWE 表明如何更改 pgfplots 中的字体系列?并未涵盖所有情况。图本身中的数字和标题中数学模式中的下标需要进一步注意。

在此处输入图片描述

\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}

答案1

如果您添加font=\sffamily\sansmath选项tikzpicture(或axis选项),所有文本将采用无衬线字体,而无需您查找所有相关样式:

\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}

相关内容