我用来groupplots
显示 2 列 6 行中的 12 个图。每行中的两个图与某种方法相关,我想在标题中指定方法名称。问题是,它只groupplots
提供label
显示每个图的功能,而不是一次显示多个图。
我目前的解决方案是标记行中的第一个图。问题是标题是根据第一个图对齐的。有时标题比图宽,看起来很奇怪。
MWE 如下:
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=2 by 2,
vertical sep=2cm,
},
height=5cm,
width=5cm,
]
% Row 1
\nextgroupplot[title=Some very long title]
\addplot coordinates {(0,1) (1,0)};
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
% Row 2
\nextgroupplot[title=Another long title]
\addplot coordinates {(0,1) (1,0)};
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
\end{groupplot}
\end{tikzpicture}
\end{document}
这当前的输出如下:
这期望输出将是(每行的标题居中):
答案1
您可以用 来命名您的组group name
(默认名称为group
)并自行放置节点。
\node[anchor=south] at ($(my plots c1r1.north east)!0.5!(my plots c2r1.north west)$){Some long title};
\node[anchor=south] at ($(my plots c1r2.north east)!0.5!(my plots c2r2.north west)$){Another long title};
代码:
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=my plots,
group size=2 by 2,
vertical sep=1cm, %%<--------- adjust this as suitable
},
height=5cm,
width=5cm,
]
% Row 1
\nextgroupplot%[title=Some very long title]
\addplot coordinates {(0,1) (1,0)};
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
% Row 2
\nextgroupplot%[title=Another long title]
\addplot coordinates {(0,1) (1,0)};
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
\end{groupplot}
\node[anchor=south] at ($(my plots c1r1.north east)!0.5!(my plots c2r1.north west)$){Some long title};
\node[anchor=south] at ($(my plots c1r2.north east)!0.5!(my plots c2r2.north west)$){Another long title};
\end{tikzpicture}
\end{document}