0

I have a similar problem to How to change the display of subfigures in List of Figures?.

I'm using the subcaption package. I dont need to show the caption of all figures but for some figures which have subfigures I want to show only the caption of the subfigure. How can I achieve this?

So I want to come from currently this:

2.1   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
     a Subcaption 1 . . . . . . . . . . . . . . . . . . . . . . . . . 6
     b Subcaption 2 . . . . . . . . . . . . . . . . . . . . . . . . . 6

to have it displayed like this:

2.1  a  Subcaption 1 . . . . . . . . . . . . . . . . . . . . . . . . . 6
     b  Subcaption 2 . . . . . . . . . . . . . . . . . . . . . . . . . 6

The code would look like this:

\documentclass{scrbook}

\usepackage{graphicx}
\usepackage{caption}
\usepackage[list=true]{subcaption}

\begin{document}
\begin{figure}[H]
  \begin{subfigure}{\textwidth}
    \includegraphics[width=textwidth]{subfigure1.jpg}
    \caption{subcaption 1}
  \end{subfigure}%
  \begin{subfigure}{\textwidth}
    \includegraphics[width=\textwidth]{subfigure2.jpg}
    \caption{subcaption 2}
  \end{subfigure}
  \caption[~]{Caption}
\end{figure}

\end{document}
  • Getting rid of the caption is easy. Adding the figure number to the subcaption is harder. Are you willing to give up subfigures and use \captionof(subfigure) instead? – John Kormylo Mar 17 '15 at 22:01
1

To get this to work, you can NOT use \caption inside the figure. In another figure, fine. Just not this one.

\firstsubcaption puts the figure number into the lof, while \nextsubcaption just puts the subfigure into the lof. \dummycaption looks like a figure caption, but otherwise does nothing.

These captions are not quite as flexible in format, but they will be centered until they reach \textwidth, then switch to hanging indentation. Feel free to play with \makecaption until you are happy.

list of figures

\documentclass{scrbook}

\usepackage{graphicx}
\usepackage{caption}% not needed, but compatible
\usepackage[list=true]{subcaption}% not needed, but compatible
\usepackage{mwe}

\makeatletter
\@ifundefined{c@subfigure}{%
  \newcounter{subfigure}[figure]%
  \renewcommand{\thesubfigure}{\alph{subfigure}}%
 }{}%
\makeatother

\newlength{\tempwidth}
\newsavebox{\tempbox}

\newcommand{\makecaption}[2]% #1 = caption head, #2 = caption text
{\savebox{\tempbox}{#1#2}%
 \ifdim\wd\tempbox>\textwidth
   \settowidth{\tempwidth}{#1}%
   \savebox{\tempbox}{\parbox{\textwidth}%
    {\hangindent=\tempwidth
     \hangafter=1
     \makebox[\tempwidth][l]{#1}#2}}%
 \fi
 \vskip\abovecaptionskip
 {\centering\usebox{\tempbox}\par}%
 \vskip\belowcaptionskip\hbox{}}

\newcommand{\firstsubcaption}[2][\empty]% #1 = short caption (optional), #2 = caption
{\refstepcounter{figure}%
 \refstepcounter{subfigure}%
 \ifx#1\empty
   \addcontentsline{lof}{figure}{\string\numberline {\thefigure}{\hbox to .5in{\thesubfigure}\ignorespaces #2 \relax}}%
 \else
   \addcontentsline{lof}{figure}{\string\numberline {\thefigure}{\hbox to .5in{\thesubfigure}\ignorespaces #1 \relax}}%
 \fi
 \makecaption{(\thesubfigure) }{#2}}

\newcommand{\nextsubcaption}[2][\empty]% #1 = short caption (optional), #2 = caption
{\refstepcounter{subfigure}%
 \ifx#1\empty
   \addcontentsline{lof}{figure}{\string\numberline { }{\hbox to .5in{\thesubfigure}\ignorespaces #2 \relax}}%
 \else
   \addcontentsline{lof}{figure}{\string\numberline { }{\hbox to .5in{\thesubfigure}\ignorespaces #1 \relax}}%
 \fi
 \makecaption{(\thesubfigure) }{#2}}

\newcommand{\dummycaption}[1][\empty]% #1 = caption text (optional)
{\ifx#1\empty\makecaption{Figure \thefigure}{}%
 \else\makecaption{Figure \thefigure: }{#1}%
 \fi}

\begin{document}
\listoffigures

\begin{figure}[H]
  \centering%
  \begin{subfigure}{.8\textwidth}
  \includegraphics[width=\textwidth]{example-image-a}%
  \firstsubcaption{subcaption 1}
  \end{subfigure}
  \begin{subfigure}{.8\textwidth}
  \includegraphics[width=\textwidth]{example-image-b}%
  \nextsubcaption{subcaption 2}
  \end{subfigure}
  \dummycaption
\end{figure}

\end{document}

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.