我发现的所有解决方案都只适用于 2020 年之前,并且不再适用于最新的 caption.sty。
我将从 MWE 开始:
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usepackage{caption,subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=my plots,
group size= 3 by 3,
horizontal sep =1.5cm,
vertical sep =2cm},
width=2in
]
\nextgroupplot[]
\addplot[] {x^0};
\nextgroupplot[]
\addplot[] {x^1};
\nextgroupplot[]
\addplot[] {x^2};
\nextgroupplot[]
\addplot[] {x^3};
\nextgroupplot[]
\addplot[] {x^4};
\nextgroupplot[]
\addplot[] {x^5};
\end{groupplot}
% Bildunterschriften
\tikzset{SubCaption/.style={
text width=2in,yshift=-3mm, align=center,anchor=north
}}
\node[SubCaption] at (my plots c1r1.south) {\captionof{subfigure}{First graph\label{subplot:eins}}};
\node[SubCaption] at (my plots c2r1.south) {\captionof{subfigure}{Second graph\label{subplot:zwei}}};
\node[SubCaption] at (my plots c3r1.south) {\captionof{subfigure}{Third graph\label{subplot:drei}}};
\node[SubCaption] at (my plots c1r2.south) {\captionof{subfigure}{Fourth graph\label{subplot:vier}}};
\node[SubCaption] at (my plots c2r2.south) {\captionof{subfigure}{Fifth graph\label{subplot:fuenf}}};
\node[SubCaption] at (my plots c3r2.south) {\captionof{subfigure}{Sixth graph\label{subplot:sechs}}};
\end{tikzpicture}
\caption{All graphs}\label{fig:plots}
\end{figure}
\end{document}
(取自https://www.matheplanet.com/matheplanet/nuke/html/viewtopic.php?topic=236653)
正如您所见,四年前这种方法是这样的,所有单个图表都有以 a) 开头的子标题,但现在每个标题都是实际的图形标题……
我还收到以下所有标题行的错误消息:
Package caption Error: Should not be used with subtype 'subfigure'.
有人知道目前可用于解决 pgf groupplot 中的标题问题的解决方案吗?
答案1
使用\subcaption
而不是\captionof{subfigure}
。\rewnewcommand\thesubfigure
可以注释掉 。
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usepackage{caption,subcaption}
% \renewcommand\thesubfigure{(\alph{subfigure})}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=my plots,
group size= 3 by 3,
horizontal sep =1.5cm,
vertical sep =2cm},
width=2in
]
\nextgroupplot[]
\addplot[] {x^0};
\nextgroupplot[]
\addplot[] {x^1};
\nextgroupplot[]
\addplot[] {x^2};
\nextgroupplot[]
\addplot[] {x^3};
\nextgroupplot[]
\addplot[] {x^4};
\nextgroupplot[]
\addplot[] {x^5};
\end{groupplot}
% Bildunterschriften
\tikzset{SubCaption/.style={
text width=2in,yshift=-3mm, align=center,anchor=north
}}
\node[SubCaption] at (my plots c1r1.south) {\subcaption{First graph\label{subplot:eins}}};
\node[SubCaption] at (my plots c2r1.south) {\subcaption{Second graph\label{subplot:zwei}}};
\node[SubCaption] at (my plots c3r1.south) {\subcaption{Third graph\label{subplot:drei}}};
\node[SubCaption] at (my plots c1r2.south) {\subcaption{Fourth graph\label{subplot:vier}}};
\node[SubCaption] at (my plots c2r2.south) {\subcaption{Fifth graph\label{subplot:fuenf}}};
\node[SubCaption] at (my plots c3r2.south) {\subcaption{Sixth graph\label{subplot:sechs}}};
\end{tikzpicture}
\caption{All graphs}\label{fig:plots}
\end{figure}
\end{document}