# Common label for a groupplot [duplicate]

This can be considered a combination of the following questions

How can a title be placed for a group of pgfplots?

Align ylabels of grouped plots at a common line

The following piece of code renders two plots, one above the other, and attaches a common ylabel to both.

\documentclass[tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage{cmbright}
%% Just some font that has serifs for maths
%% Yes; this particular combination is horrible
\usepackage{euler}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=1 by 2}]
\nextgroupplot[ylabel = ylabel, y unit = m/s]
\nextgroupplot
\end{groupplot}

\node at ($(group c1r1.west)!0.5!(group c1r2.west)$)
[xshift=-1.5cm] % Problem #1: estimated distance
{\rotatebox{90}{ylabel [$\mathrm{m/s}$]}};
% Problem #2: Copying pgfplots internals,
% i.e. /pgfplots/unit code/.code 2 args={\mathrm{#1#2}}
\end{tikzpicture}
\end{document}


There are two problems: It would be nice if the near ticks mechanics worked for this case, too, i.e. the optimal distance from both plots were determined automatically; on top of that, if units are used, the ylabel isn't just a bit of text anymore, but something more complicated; and I'd rather not reinvent that machinery.

Is there a better way to handle this?

-

## marked as duplicate by anonymous, Christian Hupfer, Papiro, Martin Schröder, barbara beetonMar 29 at 20:07

You might find the following approach helpful. Here I just add the label to the second plot (the one with the widest labels) and place it relative to the second plot's axis at 10% above. This has the advantages of (a) using the standard labelling style and (b) positioning that will vary in a sensible way with different plot sizes. The main choice being made is which plot to attach it to, the choice being based on that with the widest labels.

\documentclass{article}

\usepackage{pgfplots}
\usepgfplotslibrary{units,groupplots}

\begin{document}

\begin{tikzpicture}
\begin{groupplot}[group style={group size=1 by 2}]
\nextgroupplot