21

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}
24

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}
  • 1
    Is there any solution for styles that differ for every label? – GeMir Nov 13 '15 at 11:36
  • 1
    I would also be interested in styles differing for every label. – Olorun Dec 23 '15 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.