1

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

David Carlisle
  • 757,742

1 Answers1

2

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

David Carlisle
  • 757,742