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.

What I want to do is to have 3 PGFPlots subplots and the legend arranged in four equally sized boxes. However, when I use the following code, in the output the legend is not vertically aligned with the bottom left plot. What should I do to make it vertically aligned at the center of the bottom row, which in my opinion would be more aesthetically pleasing?

\documentclass[12pt]{article}

\usepackage{pgfplots}

\begin{document}

\begin{tabular}{cc}
  \begin{tikzpicture}
    \begin{axis}[width=0.45\textwidth,
      legend columns=1,
      legend entries={blahblahblah\\},
      legend to name=legend:aligning-subplots-legend]
      \addplot {x};
    \end{axis}
  \end{tikzpicture}
  &
  \begin{tikzpicture}
    \begin{axis}[width=0.45\textwidth]
      \addplot {x};
    \end{axis}
  \end{tikzpicture}
  \\
  \begin{tikzpicture}
    \begin{axis}[width=0.45\textwidth]
      \addplot {x};
    \end{axis}
  \end{tikzpicture}
  &
  \ref{legend:aligning-subplots-legend}
\end{tabular}

PDF output of code

share|improve this question
    
Do all of the plots have the same x and y axis ranges? –  Jake Sep 7 '12 at 5:03
    
In this case they do, which hopefully makes that easier... –  I Like to Code Sep 7 '12 at 16:07
add comment

1 Answer

up vote 1 down vote accepted

I did manage to find another post that was useful to me, see Vertically center cells of a table?

My solution and what the output looks like is below.

\documentclass[a4paper]{article}

\usepackage{array}% http://ctan.org/pkg/array
\usepackage{pgfplots}

\newcolumntype{M}{>{\centering\arraybackslash}m{\dimexpr.5\linewidth-2\tabcolsep}}

\begin{document}

\begin{figure}[h!]
  \begin{center}
    \begin{tabular}{MM}
      \begin{tikzpicture}
        \begin{axis}[width=0.45\textwidth,
            legend columns=1,
            legend entries={blahblahblah\\},
            legend to name=legend:aligning-subplots-legend]
          \addplot {x};
        \end{axis}
      \end{tikzpicture}
      &
      \begin{tikzpicture}
        \begin{axis}[width=0.45\textwidth]
          \addplot {x};
        \end{axis}
      \end{tikzpicture}
      \\
      \begin{tikzpicture}
        \begin{axis}[width=0.45\textwidth]
          \addplot {x};
        \end{axis}
      \end{tikzpicture}
      &
      \ref{legend:aligning-subplots-legend}
    \end{tabular}
  \end{center}
\end{figure}

\end{document}

PDF output of code

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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