# yticks right aligned

I have a problem with a tikz-picture concerning yticks. The plot contains two y-axes and it seems as if tikz cannot cope with that properly. I have already found this link (Aligning ticklabels in secondary y-axis in pgfplot), but texstudio has problems with compiling this solution.

The code is attached:

% This file was created by matlab2tikz.
%
%  http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz
%where you can also make suggestions and rate matlab2tikz.
%
\definecolor{mycolor1}{rgb}{0.00000,0.36078,0.58824}%
\definecolor{mycolor2}{rgb}{0.63137,0.69412,0.10196}%
%
\begin{tikzpicture}[font=\sffamily]

\begin{axis}[%
width=0.45\textwidth,
scale only axis,
xmin=0,
xmax=1,
xtick={  0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9,   1},
xlabel={geregelte Machzahl $Ma_\textrm{N,Control}~\left\lbrack-\right\rbrack$},
xmajorgrids,
separate axis lines,
every outer y axis line/.append style={mycolor1},
every y tick label/.append style={font=\color{mycolor1}},
ymin=-50,
ymax=50,
ytick={-50, -25,   0,  25,  50},
%ylabel={Druckverlust $\triangle p_t~\left\lbrack\textrm{Pa}\right\rbrack$},
ymajorgrids,
axis background/.style={fill=white}
]
table[row sep=crcr]{%
0.05    0.577365307486616\\
0.1 -0.111634692511871\\
0.2 -1.53963469251175\\
0.3 -4.40663469252468\\
};
plot [error bars/.cd, y dir = both, y explicit]
table[row sep=crcr, y error plus index=2, y error minus index=3]{%
0.05    0.577365307486616   2.02796281884957    2.02796281884957\\
0.1 -0.111634692511871  4.40885720562954    4.40885720562954\\
0.2 -1.53963469251175   10.948300604055 10.948300604055\\
0.3 -4.40663469252468   25.0851926876272    25.0851926876272\\
};
\end{axis}

\begin{axis}[%
width=0.45\textwidth,
scale only axis,
xmin=0,
xmax=1,
%xtick={  0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9,   1},
every outer y axis line/.append style={mycolor2},
every y tick label/.append style={font=\color{mycolor2}},
ymin=-1,
ymax=1,
ytick pos=right,
ylabel near ticks,
ytick={  -1, -0.8, -0.6, -0.4, -0.2,    0,  0.2,  0.4,  0.6,  0.8,    1},
ylabel={Abweichung der Machzahl $\frac{Ma_\textrm{N,True}}{Ma_\textrm{N,Control}}-1~\left\lbrack\%\right\rbrack$},
axis x line*=bottom,
axis y line*=right
]

• Hi, welcome. I don't know exactly what you tried, but if you're referring to the \widthof method, then you're affected by a change that was made between version 2.1 and 3 of TikZ. Use yticklabel style={text width=width("$-2.0$"),align=right} instead. – Torbjørn T. Apr 10 '17 at 17:51