[Tex/LaTex] individual tick label style with pgfplots

labelspgfplots

given the following code, I want to modify the tick labels in such a way, that for negative values of x, the labels are located above the x-axis. How can I realize this?

\documentclass{report}
\usepackage{pgf}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
axis x line=middle,
axis y line=middle,
width=10cm,
height=10cm,
scale only axis,
xmin=-5,
xmax=5,
xtick={-4, -2, 0,  2,  4},
xticklabels={$-4\pi$, $-2\pi$, $0$, $2\pi$, $4\pi$},
extra x ticks={-4, -2},
ymin=-1.4,
ymax=1.4,
ytick={-1,  0,  1}]
\end{axis}
\end{tikzpicture}%
\end{document}

Best Answer

Since you only need two different styles (as opposed to styles that differ for every label), you can use extra x ticks for the negative labels:

\documentclass{report}
\usepackage{pgf}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
axis lines*=middle,
width=10cm,
height=10cm,
scale only axis,
xmin=-5,
xmax=5,
xtick={2,  4},
xticklabels={$2\pi$, $4\pi$},
extra x ticks={-4, -2},
extra x tick labels={$-2\pi$, $-4\pi$},
extra x tick style={
    xticklabel style={yshift=0.5ex, anchor=south}
},
ymin=-1.4,
ymax=1.4,
ytick={-1,  0,  1}]
\end{axis}
\end{tikzpicture}%
\end{document}
Related Question