5

I am new to LaTeX. I am not sure how to frame my question. But I will frame it so that it is understandable.

I would like to make a subfigure, but the caption must be

caption of subfigure a-1 caption of subfigure a-2

caption of subfigure b-1 caption of subfigure b-2

                 `caption  of entire figure`

I tried using subfigure, but I am getting continuously a,b,c,d, but i need to name them as as mentioned above (a-1, a-2, b-1, b-2). In my situation, there are chances that the sub figures might be in different pages.

  • There are several different subfigure and subcaption packages, but you really don't need any of them. Just put them all into a tabular, then use a regular caption at the bottom. – John Kormylo Dec 14 '14 at 14:28
4

This uses the same idea as subequations of 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}

enter image description here

EDIT

The above code doesn't really work if more figure environments use subsubcaption. Here's a workaround that tries to work well also with \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}

enter image description here

The “continuation” figure has labels c and d, while the following “new” one has a and b again.

  • @egreg..Thank you very much. This is what I was expecting. 1. But, for me, the counter is starting from c (Eg: c-1,c-2): 2. Also I have multiple subfigures. The figures are not moving automatically to next page, instead the sub-figures are in bottom margin of the current page. For this I tried to remove '\ignorespacesafterend', but this doesn't help me. – user8162 Dec 14 '14 at 17:34
  • @user8162 A figure environment is never split across pages. You can look at \ContinuedFloat in caption. – egreg Dec 14 '14 at 17:35
  • Thanks.. \continuedfloat worked fine. I am extremely sorry for asking more questions. But still the counter starts from c. – user8162 Dec 14 '14 at 17:44
  • @user8162 For the counter starting from c we need a minimal example. Open a new question. – egreg Dec 14 '14 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.