我发现在手册中很难找到我想要的东西pgfplots
。特别是,我想个性化刻度标记标签的排版方式。找到正确的关键字非常麻烦。例如,在下面的代码中,我希望只将刻度标记设置为 san serif;其他所有内容都应采用正常字体。但是,我所做的一切似乎都没有什么不同。
% arara: pdflatex
% arara: pdflatex
% arara: open
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
%%\pgfplotsset{compat=1.3}%%
\pgfplotsset{every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={->,color=blue}, % arrows on the axis
every x tick label/.append style={font=\itshape,yshift=0.75ex,rotate=0},
every y tick label/.append style={font=\scriptsize\sffamily,xshift=0.75ex},
every axis x label/.style={at={(ticklabel cs:0.5)},anchor=near ticklabel},
every axis y label/.style={at={(ticklabel cs:0.5)},anchor=near ticklabel,rotate=90},
},
x=1.65pt,
y=2.25pt,
}
\begin{document}
\newcommand\aemass{(50 / 2 ^ ( x/28) )}
\begin{tikzpicture}
\begin{axis}[
%<only applies to titles but not tick labels>% font=\sffamily,
title={Mass of Strontium-90 after $t$-days \textsf{1,2,3,4,5,}},
xlabel={time (in days)},
ylabel={mass (in milligrams)},
xmin=0,xmax=170,
ymin=0,ymax=64,
grid=both,
xtick={0,10,...,160},
ytick={0,2,5,...,60},
]
\addplot [domain=0:170,samples=64]({x},{\aemass});
\end{axis}
\end{tikzpicture}
\end{document}
关键字font
respect 会改变字体的大小,但不改变字体的字形(例如 san serif、italic 或 bold)。
虽然如果有人告诉我应该在这里使用什么关键字会很好,但如果有人能告诉我我可以编写一个宏来处理格式并了解pgfplots
如何使用该宏就更好了。
答案1
这是因为标签处于数学模式,因此它们不会立即应用。您可以通过重新定义标签打印命令来更改此行为。我在这里这样做只是为了 x 来显示差异。或者,您可以通过 Lua/XELaTeX 使用 sanserif 数学字体作为标签
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
%%\pgfplotsset{compat=1.3}%%
\pgfplotsset{every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={->,color=blue}, % arrows on the axis
every x tick label/.append style={font=\itshape,yshift=0.75ex,rotate=0},
every y tick label/.append style={font=\scriptsize\sffamily,xshift=0.75ex},
every axis x label/.style={at={(ticklabel cs:0.5)},anchor=near ticklabel},
every axis y label/.style={at={(ticklabel cs:0.5)},anchor=near ticklabel,rotate=90},
},
x=1.65pt,
y=2.25pt,
}
\begin{document}
\newcommand\aemass{(50 / 2 ^ ( x/28) )}
\begin{tikzpicture}
\begin{axis}[
font=\sffamily,
xticklabel={\pgfmathprintnumber[assume math mode=true]{\tick}},
title={Mass of Strontium-90 after $t$-days \textsf{1,2,3,4,5,}},
xlabel={time (in days)},
ylabel={mass (in milligrams)},
xmin=0,xmax=170,
ymin=0,ymax=64,
grid=both,
xtick={0,10,...,160},
ytick={0,2,5,...,60},
]
\addplot [domain=0:170,samples=64]({x},{\aemass});
\end{axis}
\end{tikzpicture}
\end{document}