我使用 pgfplots 创建了一个坐标系。现在我希望字体是无衬线的,所以我尝试了\sffamily
文档开始后的命令(就像示例中一样)。这样,除了 y 轴标签之外,所有内容都是无衬线的。我尝试了,\begin{tikzpicture}[font=\sffamily]
但\pgfplotsset{ticklabel style = {font=\sffamily}, y axis label/.append style={font=\sffamily}, }
所有这些都得到了代码下方显示的相同结果。
有人知道如何获取无衬线字体的 y 轴字体吗?
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\begin{document}
\sffamily
\begin{tikzpicture}
\begin{axis}[
width=14cm,
height=7cm,
scale only axis,
xmin=-5,xmax=105,
ymin=0,ymax=12,
x dir=reverse,
axis y line*=right,
axis x line*=top,
xtick=\empty,
extra x ticks={0,10,20,30,40,50,60,70,80,90,100},
extra x tick labels={{0},{10},{20},{30},{40},{50},{60},{70},{80},{90},{100}},
every x tick/.style={},
xlabel=Palmfett / Gew.\%,
xlabel style={at={(0.5,1.225)}},
]
\end{axis}
\begin{axis}[
width=14cm,
height=7cm,
scale only axis,
xmin=-5 ,xmax=105,
ymin=0, ymax=12,
axis y line*=left,
axis x line*=bottom,
xtick=\empty,
extra x ticks={0,10,20,30,40,50,60,70,80,90,100},
extra x tick labels={{0},{10},{20},{30},{40},{50},{60},{70},{80},{90},{100}},
extra x tick style={grid=major},
every x tick/.style={},
xlabel=Bienenwachs / Gew.\%,
ylabel=Martenshärte / N/mm$^2$
]
\end{axis}
\end{tikzpicture}
\end{document}
答案1
如果你只需要更改某些元素的字体,那么你可以定义它们
\begin{tikzpicture}
\begin{axis}[
width=14cm,
height=7cm,
scale only axis,
xmin=-5,xmax=105,
ymin=0,ymax=12,
x dir=reverse,
axis y line*=right,
axis x line*=top,
xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
yticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
xlabel=Palmfett / Gew.\%,
xlabel style={at={(0.5,1.225)}},
]
\end{axis}
\begin{axis}[
width=14cm,
height=7cm,
scale only axis,
xmin=-5 ,xmax=105,
ymin=0, ymax=12,
axis y line*=left,
axis x line*=bottom,
xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
yticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
xlabel=Bienenwachs / Gew.\%,
ylabel=Martenshärte / N/mm$^2$
]
\end{axis}
\end{tikzpicture}
这将保持轴标签不变,但无衬线的 tikc 标签不会经过额外的标签声明。
答案2
刻度标签是在数学模式下设置的,即$0$
等等。因此,\sffamily
那里不尊重。您可以\sffamily
按照答案强制在数学模式下对这个问题或者ytick=\empty
像对 s 所做的那样制作xtick
并使用extra y tick
s。此外,只需传递[font=\sffamily]
给即可tikzpicture
更改字体。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
%\usepackage{cmbright}
\pgfplotsset{compat=1.12}%,tick label style={font=\sffamily},}
\begin{document}
%\sffamily
\begin{tikzpicture}[font=\sffamily]
\begin{axis}[
width=14cm,
height=7cm,
scale only axis,
xmin=-5,xmax=105,
ymin=0,ymax=12,
x dir=reverse,
axis y line*=right,
axis x line*=top,
xtick=\empty,
extra x ticks={0,10,20,30,40,50,60,70,80,90,100},
extra x tick labels={{0},{10},{20},{30},{40},{50},{60},{70},{80},{90},{100}},
ytick=\empty,
extra y ticks={0,2,4,6,8,10,12},
extra y tick labels={{0},{2},{4},{6},{8},{10},{12}},
every x tick/.style={},
xlabel=Palmfett / Gew.\%,
xlabel style={at={(0.5,1.225)}},
]
\end{axis}
\begin{axis}[
width=14cm,
height=7cm,
scale only axis,
xmin=-5 ,xmax=105,
ymin=0, ymax=12,
axis y line*=left,
axis x line*=bottom,
xtick=\empty,
extra x ticks={0,10,20,30,40,50,60,70,80,90,100},
extra x tick labels={{0},{10},{20},{30},{40},{50},{60},{70},{80},{90},{100}},
extra x tick style={grid=major},
ytick=\empty,
extra y ticks={0,2,4,6,8,10,12},
extra y tick labels={{0},{2},{4},{6},{8},{10},{12}},
every x tick/.style={},
xlabel=Bienenwachs / Gew.\%,
ylabel=Martenshärte / N/mm$^2$
]
\end{axis}
\end{tikzpicture}
\end{document}