Eu sou novo no LaTeX. Não tenho certeza de como enquadrar minha pergunta. Mas vou enquadrar para que seja compreensível.
Gostaria de fazer uma subfigura, mas a legenda deve ser
caption of subfigure a-1
caption of subfigure a-2
caption of subfigure b-1
caption of subfigure b-2
`caption of entire figure`
Tentei usar subfigura, mas estou obtendo continuamente a,b,c,d
, mas preciso nomeá-los conforme mencionado acima (a-1, a-2, b-1, b-2). Na minha situação, há chances de que as subfiguras estejam em páginas diferentes.
Responder1
Isso usa a mesma ideia subequations
de 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}
EDITAR
O código acima realmente não funciona se mais ambientes de figuras usarem arquivos subsubcaption
. Aqui está uma solução alternativa que tenta funcionar bem também com o \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}
A figura de “continuação” tem os rótulos c e d, enquanto a figura “nova” seguinte tem a e b novamente.