以下代码中的错误似乎出在的以下选项axis
中pgfplot
。
ticklabel style={font=\tiny,fill=none},
extra x ticks={-3.14159, -1.5708, 1.5708, 3.14159},
extra x tick labels={${\makebox[0pt][r]{\tiny-}$\pi$}$, $-\frac{\pi}{2}$, $\frac{\pi}{2}$, $\pi$},
我不希望前两个刻度标记的标签中的负号发生位移$\pi$ and $\frac{\pi}{2}$
。
这段代码有什么问题?如何让字体排版显示减号\tiny
?减号和 之间会插入适当的空格$\pi$
吗$\frac{\pi}{2}$
?
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=3in,axis on top,clip=false,
axis lines=middle,
xmin=-3.75,xmax=3.75,
domain=-3.75:3.75,
ymin=-0.25,ymax=2.25,
restrict y to domain=-0.25:2.25,
enlargelimits={abs=0.5cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=none},
xtick={\empty},ytick={\empty},
extra x ticks={-3.14159, -1.5708, 1.5708, 3.14159},
extra x tick labels={${\makebox[0pt][r]{\tiny-}$\pi$}$, $-\frac{\pi}{2}$, $\frac{\pi}{2}$, $\pi$},
extra y ticks={2},
extra y tick style={y tick label style={anchor=south east}},
xlabel=$x$,ylabel=$y$,
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot [samples=501, domain=-3.5:3.5, blue] {1 + cos(deg(x))};
\addplot [samples=2, latex-latex, domain=-3.5:3.5] {1};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您需要数学模式-
。尺寸变化必须在数学模式之外,但您不需要在此处进行尺寸变化。
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=3in,axis on top,clip=false,
axis lines=middle,
xmin=-3.75,xmax=3.75,
domain=-3.75:3.75,
ymin=-0.25,ymax=2.25,
restrict y to domain=-0.25:2.25,
enlargelimits={abs=0.5cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=none},
xtick={\empty},ytick={\empty},
extra x ticks={-3.14159, -1.5708, 1.5708, 3.14159},
extra x tick labels={$\llap{$-$}\pi$, $\llap{$-$}\frac{\pi}{2}$, $\frac{\pi}{2}$, $\pi$},
extra y ticks={2},
extra y tick style={y tick label style={anchor=south east}},
xlabel=$x$,ylabel=$y$,
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot [samples=501, domain=-3.5:3.5, blue] {1 + cos(deg(x))};
\addplot [samples=2, latex-latex, domain=-3.5:3.5] {1};
\end{axis}
\end{tikzpicture}
\end{document}