在軸上排版刻度線,以便忽略減號所佔用的空間

在軸上排版刻度線,以便忽略減號所佔用的空間

以下程式碼中的錯誤似乎是axispgfplot.

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}

相關內容