Menu

#173 [extra ticks][axis labels] axis label alignment wrong when ticks are outside and there are extra ticks

v1.0 (example)
open
7
2017-06-02
2017-06-02
No

This bug was "reported" in the TeX.SX question https://tex.stackexchange.com/q/372868. Here a more minimal MWE also showing the problem for the xlabel.

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture}
        \pgfmathsetlengthmacro{\MajorTickLength}{10mm}
        \pgfmathsetlengthmacro{\ExtraMajorTickLength}{5mm}
        \fill (-4,-4) circle (2pt);
        % ---------------------------------------------------------------------
    \begin{axis}[
        xlabel={xlabel},
        ylabel={ylabel},
        % ---------------------------------------------------------------------
        % this gives you the "correct" ylabel positioning
        % (To see that this is really the "right" position, comment the
        %  this block and the extra tick lines. Watch the updating
        %  PDF where you will not see a jump of the ylabel.
        %  Comment only this block to see the jump to the "blue" nodes.)
        xlabel style={
            yshift=\MajorTickLength + \ExtraMajorTickLength,
        },
        ylabel style={
            yshift=-\MajorTickLength - \ExtraMajorTickLength,
        },
        % ---------------------------------------------------------------------
        extra x ticks={2.5},
        extra y ticks={2.5},
        % ---
        extra tick style={
            major tick length=\ExtraMajorTickLength,   % <-- (this adds a shift as well)
        },
        xtick distance=5,
        ytick distance=5,
        xtick pos=left,
        ytick pos=left,
        tick align=outside,         % <-- this causes the shift
        major tick length=\MajorTickLength,
        clip mode=individual,
    ]
        \addplot {x};

        % ---------------------------------------------------------------------
        % for debugging purposes only to find out, what is happending with
        % the ylabel positioning
            \pgfmathsetlengthmacro{\xshift}{
                % offset when ticks are inside (roughly estimated)
                -4.5ex
                % additional offset when ticks are outside
                - \pgfkeysvalueof{/pgfplots/major tick length}
                % additional offset of extra ticks
                - (\pgfkeysvalueof{/pgfplots/major tick length} + \ExtraMajorTickLength)
            }
        \node [rotate=90,anchor=south,text=blue]
            at ([xshift=\xshift]rel axis cs:0,0.5) {ylabel};

            \pgfmathsetlengthmacro{\yshift}{
                % offset when ticks are inside (roughly estimated)
                -3.5ex
                % additional offset when ticks are outside
                - \pgfkeysvalueof{/pgfplots/major tick length}
                % additional offset of extra ticks
                - (\pgfkeysvalueof{/pgfplots/major tick length} + \ExtraMajorTickLength)
            }
        \node [anchor=north,text=blue]
            at ([yshift=\yshift]rel axis cs:0.5,0) {xlabel};
        % ---------------------------------------------------------------------
    \end{axis}
\end{tikzpicture}
\end{document}

Discussion