[Tex/LaTex] Individual Tick style for each Tick

pgfplotstikz-pgf

I would like to raise the left Tick over the x-axis so it doesn't clip into the graph. However If I add a second "Extra x ticks" definition the first definition gets overwritten. How can I achieve an individual tickstyle for each tick. This question is related however it doesn't work for three different tickstyles. (See comments in the answer)

\documentclass{article}
\usepackage{multirow}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pgfplots}

\begin{document}
\begin{figure}[tb]
\begin{tikzpicture}[baseline] \begin{axis}[
   ylabel style={rotate=-90},
   xtick = 0,
   ytick = 0,
   xtick style={draw=none},
   xmin = -5,
   xmax = 5,
   ylabel={$I$},
   xlabel={$U$},
   extra x ticks       = {-2,2},
   extra x tick labels = {$ -E_{ \text{t}} $, $ E_{ \text{t2}} $},
   extra x tick style  = { grid = major },
axis y line=middle,
axis x line=middle,
]
\addplot[blue,samples=21]  
        coordinates {  
            (-5,-5)
            (-2,-1)
            (2,1)
            (5,5)
            };
\end{axis}%
\end{tikzpicture}%
\end{figure}
\end{document}

enter image description here

Best Answer

In the answer to the linked question, you will see xtick is used for positive values of x, while extra x ticks is for the negative values of x. You need to do something similar here. (I removed a couple unnecessary packages as well.)

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{figure}[tb]
\begin{tikzpicture}[baseline] \begin{axis}[
   ylabel style={rotate=-90},
   xtick       = {2},
   xticklabels = {$ E_{ \mathrm{t2}} $},
   grid = major,
   ytick = 0,
   xmin = -5,
   xmax = 5,
   ylabel={$I$},
   xlabel={$U$},
   extra x ticks       = {-2},
   extra x tick labels = {$ -E_{ \mathrm{t}} $},
   extra x tick style  = { grid = major,xticklabel style={yshift=0.5ex, anchor=south}
   },
axis y line=middle,
axis x line=middle,
]
\addplot[blue,samples=21]  
        coordinates {  
            (-5,-5)
            (-2,-1)
            (2,1)
            (5,5)
            };
\end{axis}%
\end{tikzpicture}%
\end{figure}
\end{document}

enter image description here

Edit:

One way to get a third tick that is different from the other two is to define a second set of axes with the same limits as the first, and then add the ticks to the new axes.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{figure}[tb]
\begin{tikzpicture}[baseline] 
\begin{axis}[
   ylabel style={rotate=-90},
   xtick       = {2},
   xticklabels = {$ E_{ \mathrm{t2}} $},
   grid = major,
   ytick = \empty,
   xmin = -5,
   xmax = 5,
   ylabel={$I$},
   xlabel={$U$},
   extra x ticks       = {-2},
   extra x tick labels = {$ -E_{ \mathrm{t}} $},
   extra x tick style  = { grid = major,xticklabel style={yshift=0.5ex, anchor=south}
   },
axis y line=middle,
axis x line=middle,
]
\addplot[blue]
        coordinates {  
            (-5,-5)
            (-2,-1)
            (2,1)
            (5,5)
            };
\end{axis}%
\begin{axis}[
   xmin = -5,
   xmax = 5,
    xtick       = {4},
   ytick = \empty,
    xticklabels = {$ E_{ \mathrm{t4}} $},
    xticklabel style={blue,yshift=0.5ex, rotate=30},
    axis x line=middle,
    axis y line=middle,
]
\addplot[draw=none] {x};
\end{axis}

\end{tikzpicture}%
\end{figure}
\end{document}

enter image description here

Related Question