# Align ylabels of grouped plots at a common line

I use the groupplots library of pgfplots to stack several plots above each other. The y tick label of the two plots have different width as the y axes of the plots are in different scales. As long as I don't set \pgfplotsset{compat=1.6}, pgfplots does not consider the y tick label's width at all and prints the ylabel right across the tick labels. When I activate the compat=1.6 option, the size of the tick labels is considered when placing the label, but in this case (cf. MWE below), the ylabels are placed relative to the tick labels of the concerning plot and therefore the labels of the two plots have different distance to the border of the whole plot group.

Is there a simple command to align the ylabels at a common vertical line instead of aligning each of them relative to its respective plot?

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.6}

\begin{document}
\begin{tikzpicture}
\begin{groupplot}
[group style={group size = 1 by 2}]
\nextgroupplot[ylabel = Text]
\addplot coordinates {(0,0) (1,0.1)};
\nextgroupplot[ylabel=Text]
\addplot coordinates {(0,0) (1,2)};
\end{groupplot}
\end{tikzpicture}
\end{document}


-
So you want the label to automatically placed so that it accommodates the largest ticklabels, right? Or do you merely want to manually set the spacing? –  Jake Oct 5 '12 at 20:16
I would prefer to have this computed automatically. As the left borders of the plots are all aligned, one would just have to compute and/or store the width of the widest y tick label and apply it to all other plots. My hope was that there was already some option in pgfplots itself which toggles this and which I just haven't recognized yet. –  Benedikt Bauer Oct 5 '12 at 21:24
At the moment, this option isn't available, because the plots in a groupplots environment are processed sequentially, so the ticklabels of one plot can't influence the label position of an earlier one. –  Jake Oct 5 '12 at 21:28

You can redefine the every axis y label style by increasing the xshift value as required.

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.6,
ylabsh/.style={every axis y label/.style={at={(0,0.5)}, xshift=#1, rotate=90}}}

\begin{document}
\begin{tikzpicture}
\begin{groupplot}
[group style={group size = 1 by 2}, ylabsh=-5em]
\nextgroupplot[ylabel = Text]
\addplot coordinates {(0,0) (1,0.1)};
\nextgroupplot[ylabel=Text]
\addplot coordinates {(0,0) (1,2)};
\end{groupplot}
\end{tikzpicture}
\end{document}


Now it doesn't matter the running version.

-
I would suggest using ylabel absolute, every axis y label/.append style={yshift=1.5em} instead of manually setting all the relevant options. –  Jake Oct 5 '12 at 20:35
@Jake, I think it's a bit unintuitive to use yshift for a horizontal shift, so I continue preferring my syntax. Eventually it's just a matter of taste. –  Luigi Oct 5 '12 at 20:57
As commented above I would prefer a solution that does this automatically. Imagine a situation where you have to draw a lot of similar graphs: if you set the shift to a fixed value globally you would end up with some graphs that look weird as they wouldn't need this tweak at all. If you don't do it globally you have to fiddle around on every single graph to get the right values for the shift and have to take care every time you change something. –  Benedikt Bauer Oct 5 '12 at 21:29
@BenediktBauer, as Jake said, some tweaking is necessary, and it is even usual in typography. However, are you sure that in the same document there will be need to select so many different shift lenghts? In the end, you could define a new style and pass the shift as an argument or assign it once for all. I did it for you in the edited version of my answer. –  Luigi Oct 6 '12 at 8:07