在 pgfplots 中使用 \sffamily 作为刻度标签

在 pgfplots 中使用 \sffamily 作为刻度标签

可能重复:
如何更改 pgfplots 中的字体系列?

我正在尝试在 pgfplots 中使用 sf 字体作为刻度标签。我已经看到过很多这样的问题,但它们都有更复杂的问题,我自己找不到合适的解决方案。

我的 MWE:

\documentclass[12pt,a4paper]{report}
\usepackage[latin1]{inputenc}
\usepackage{pgfplots}
\usepackage{helvet}
\pgfplotsset{compat=1.3}
\begin{document}
\begin{figure}
\centering

\pgfplotsset{
every axis label/.append style={font=\huge\sffamily},
tick label style={font=\sffamily\huge},
}

\begin{tikzpicture}
\begin{axis}[
height=8cm,
width=15cm,
xlabel = {x3456},
ylabel = {y},
domain = 0:1,
xtick={0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0},
ytick={0.0,0.1,0.2,0.3,0.4,0.5},
grid=major,
no markers,
cycle list name=linestyles
]
\addplot {0.5-abs(x-0.5)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

这使

平均能量损失

正如您所看到的,\sffamily适用于轴标签,但不适用于勾选标签。奇怪的是,它对\huge刻度标签确实有效。

我如何将刻度标签更改为\sffamily

答案1

如果我的评论勾选标签被视为正确的数学表达式,则必须使用数学模式无衬线字体来使其成为无衬线字体。另一方面,轴标签被视为普通文本,因此您必须使用 \sffamily使其变为无衬线文本。

因此,解决方案是:

\documentclass[12pt,a4paper]{report}
\usepackage[latin1]{inputenc}
\usepackage{pgfplots}
\usepackage{helvet}
\usepackage[eulergreek]{sansmath}
\pgfplotsset{
tick label style = {font=\sansmath\sffamily},
every axis label/.append style={font=\sffamily\footnotesize},
}
\pgfplotsset{compat=1.3}
\begin{document}
\begin{figure}
\centering

\begin{tikzpicture}
\begin{axis}[
height=8cm,
width=15cm,
xlabel = {x3456},
ylabel = {y3456},
domain = 0:1,
xtick={0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0},
ytick={0.0,0.1,0.2,0.3,0.4,0.5},
grid=major,
no markers,
cycle list name=linestyles
]
\addplot {0.5-abs(x-0.5)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

我不知道为什么,但只使用

every axis label = {font=\sffamily\footnotesize}

对我来说不起作用,所以我不得不使用

every axis label/.append style={font=\sffamily\footnotesize}.

使用上述代码,输出为

在此处输入图片描述

相关内容