我是 LaTeX 新手。我不确定如何表达我的问题。但我会以易于理解的方式表达。
我想制作一个子图,但标题必须是
caption of subfigure a-1
caption of subfigure a-2
caption of subfigure b-1
caption of subfigure b-2
`caption of entire figure`
我尝试使用子图,但不断出现a,b,c,d
,但我需要按上面提到的方式命名它们 (a-1、a-2、b-1、b-2)。 在我的情况下,子图可能位于不同的页面中。
答案1
subequations
这使用了与相同的想法amsmath
。
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\makeatletter
\newcounter{parentsubcaption}
\newenvironment{subsubcaption}
{\refstepcounter{sub\@captype}%
\protected@edef\theparentsubcaption{\@nameuse{thesub\@captype}}%
\setcounter{parentsubcaption}{\value{sub\@captype}}%
\setcounter{sub\@captype}{0}%
\@namedef{thesub\@captype}{\theparentsubcaption--\arabic{sub\@captype}}%
\ignorespaces
}{%
\setcounter{sub\@captype}{\value{parentsubcaption}}%
\ignorespacesafterend
}
\makeatother
\begin{document}
\begin{figure}
\centering
\begin{subsubcaption}
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure a--1}\label{a--1}
\end{subfigure}\qquad
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure a--2}\label{a--2}
\end{subfigure}
\end{subsubcaption}
\begin{subsubcaption}
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure b--1}\label{b--1}
\end{subfigure}\qquad
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure b--2}\label{b--2}
\end{subfigure}
\end{subsubcaption}
\caption{caption of entire figure}
\end{figure}
References:
\ref{a--1} and \subref{a--1};
\ref{b--1} and \subref{b--1}.
\end{document}
编辑
如果更多图形环境使用 ,则上述代码实际上不起作用subsubcaption
。这里有一个解决方法,尝试与 配合使用\ContinuedFloat
。
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{etoolbox}
\makeatletter
\newif\ifsubsubcaption@ContinuedFloat
\newif\ifsubsubcaption@nonfirst
\patchcmd{\ContinuedFloat}
{\caption@ContinuedFloat}
{\subsubcaption@ContinuedFloattrue\caption@ContinuedFloat}
{}{}
\newcounter{parentsubcaption}
\newenvironment{subsubcaption}
{\refstepcounter{sub\@captype}%
\protected@edef\theparentsubcaption{\@nameuse{thesub\@captype}}%
\setcounter{parentsubcaption}{\value{sub\@captype}}%
\setcounter{sub\@captype}{0}%
\@namedef{thesub\@captype}{\theparentsubcaption--\arabic{sub\@captype}}%
\ignorespaces
}{%
\setcounter{sub\@captype}{\value{parentsubcaption}}%
\ignorespacesafterend
}
\BeforeBeginEnvironment{subsubcaption}{%
\ifsubsubcaption@ContinuedFloat
\else
\ifsubsubcaption@nonfirst
\else
\subsubcaption@nonfirsttrue
\setcounter{sub\@captype}{0}%
\fi
\fi
}
\makeatother
\begin{document}
\begin{figure}
\centering
\begin{subsubcaption}
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure a--1}\label{a--1}
\end{subfigure}\qquad
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure a--2}\label{a--2}
\end{subfigure}
\end{subsubcaption}
\begin{subsubcaption}
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure b--1}\label{b--1}
\end{subfigure}\qquad
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure b--2}\label{b--2}
\end{subfigure}
\end{subsubcaption}
\caption{caption of entire figure}
\end{figure}
References:
\ref{a--1} and \subref{a--1};
\ref{b--1} and \subref{b--1}.
\begin{figure}
\ContinuedFloat
\centering
\begin{subsubcaption}
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure c--1}\label{c--1}
\end{subfigure}\qquad
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure c--2}\label{c--2}
\end{subfigure}
\end{subsubcaption}
\begin{subsubcaption}
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure d--1}\label{d--1}
\end{subfigure}\qquad
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure d--2}\label{d--2}
\end{subfigure}
\end{subsubcaption}
\caption{caption of entire figure (continued)}
\end{figure}
\begin{figure}
\centering
\begin{subsubcaption}
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure a--1}\label{a--1-x}
\end{subfigure}\qquad
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure a--2}\label{a--2-x}
\end{subfigure}
\end{subsubcaption}
\begin{subsubcaption}
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure b--1}\label{b--1-x}
\end{subfigure}\qquad
\begin{subfigure}{5cm}
\includegraphics[width=\linewidth]{example-image}
\caption{caption of subfigure b--2}\label{b--2-x}
\end{subfigure}
\end{subsubcaption}
\caption{caption of entire figure}
\end{figure}
\end{document}
“延续”图形有标签 c 和 d,而接下来的“新”图形又有 a 和 b。