Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

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}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
  \begin{groupplot}[group style={group size=1 by 2}]
    \nextgroupplot[ylabel = ylabel, y unit = m/s]
    \addplot coordinates {(0,0) (1,1) (2,2)};
    \nextgroupplot
    \addplot coordinates {(0,2) (1,1000) (2,0)};
  \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}

Rendering

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?

share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

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.

Sample output

\documentclass{article}

\usepackage{pgfplots}
\usepgfplotslibrary{units,groupplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}
  \begin{groupplot}[group style={group size=1 by 2}]
    \nextgroupplot
    \addplot coordinates {(0,0) (1,1) (2,2)};
    \nextgroupplot[ylabel=ylabel,y unit=m/s,
      every axis y label/.append style={at=(ticklabel cs:1.1)}]
    \addplot coordinates {(0,2) (1,1000) (2,0)};
  \end{groupplot}
\end{tikzpicture}

\end{document}
share|improve this answer
    
Thank you, I've used your approach, it certainly feels less hackish than mine. :) –  anonymous Mar 29 at 17:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.