我想要做的是将 3 个 PGFPlots 子图和图例排列在四个大小相同的框中。但是,当我使用以下代码时,输出中的图例未与左下角的图垂直对齐。我应该怎么做才能使其垂直对齐到底行的中心,在我看来这会更美观?
\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}
答案1
我确实找到了另一篇对我有用的帖子,请参阅垂直居中表格单元格?
我的解决方案和输出如下。
\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}