0

I am trying to use the subcaption package (not subfig) to generate the labels of the subfigures beside the figure.

I have found many similar questions, but all answers (like this one) use subfigand floatrow. I have tried using floatrow with subcaption (see MWI below), but I could not generate the same behaviour. What am I missing?

The subcaption manual explicitly states that

[f]or a more advanced usage of the sub-caption feature of the caption package, please take a look at the floatrow package

but the floatrow manual only gives an example of a caption beside the figure using subfig (p.75).

So any help is greatly appreciated.

MWI:

\documentclass{scrartcl}

\usepackage{graphicx}
\usepackage[font=footnotesize,figurewithin=none]{caption}
\usepackage{subcaption}
\captionsetup{subrefformat=parens} % will result in references (typeset with \ref) like  1a  but sub-references (typeset with\subref) like  (a)
\usepackage{floatrow}
\floatsetup[subfigure]{style=plain,subcapbesideposition=top}
%\usepackage{subfig} % not compatible with subcaption

\begin{document}

\begin{figure}
  \centering
  \begin{subfigure}[t]{0.7\textwidth}
    \centering
    \includegraphics[width=0.7\textwidth]{example-image-a}
    \caption{}
    \label{subfig:a}
  \end{subfigure}
  \\
  \begin{subfigure}[t]{0.49\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-b}
    \caption{}
    \label{subfig:b}
  \end{subfigure}
  \hfill
  \begin{subfigure}[t]{0.49\textwidth}
    \centering
     \includegraphics[width=\textwidth]{example-image-c}
    \caption{}
    \label{subfig:c}
  \end{subfigure}
  \caption{Caption for all subfigs: \subref{subfig:a},\subref{subfig:b}, \subref{subfig:c}}
  \label{fig}
\end{figure}

\end{document}

Output of MWI:

Output of MWI

2

Rather than figure out how to make floatrow work, it was easier just to fake it.

It should be noted that the [t] option of subfigure refers to the first baseline, not the absolute top, so what it does is align the bottoms of the images instead of the captions. To align the tops you need to use \raisebox. In fact, there is no reason to put the images into subfigures at all (just the captions).

The \raisebox for the caption was to automatically produce a gap between rows.

\documentclass{scrartcl}

\usepackage{graphicx}
\usepackage[font=footnotesize,figurewithin=none]{caption}
\usepackage{subcaption}
\captionsetup{subrefformat=parens} % will result in references (typeset with \ref) like  1a  but sub-references (typeset with\subref) like  (a)
%\usepackage{subfig} % not compatible with subcaption

\newcommand{\sidecaption}[1]% #1 = label name
{\raisebox{\abovecaptionskip}{\begin{subfigure}[t]{1.6em}
  \caption[singlelinecheck=off]{}% do not center
  \label{#1}
\end{subfigure}}\ignorespaces}

\begin{document}

\begin{figure}
  \centering
  \sidecaption{subfig:a}
  \raisebox{-\height}{\includegraphics[width=0.45\textwidth]{example-image-a}}

  \sidecaption{subfig:b}
  \raisebox{-\height}{\includegraphics[width=0.45\textwidth]{example-image-b}}%
  \hfill
  \sidecaption{subfig:c}
  \raisebox{-\height}{\includegraphics[width=0.45\textwidth]{example-image-c}}
  \caption{Caption for all subfigs: \subref{subfig:a},\subref{subfig:b}, \subref{subfig:c}}
  \label{fig}
\end{figure}

\end{document}

demo


It should be noted that this is only one of many possible ways to format a side caption. The following does not use the subcaption package at all. OTOH, it does not write an entry for the \listoffigures either.

\newcounter{subfigure}[figure]% not needed with subcaption
\renewcommand{\thesubfigure}{\alph{subfigure}}

\newcommand{\sidecaption}[1]% #1 = label name
{\rule{0pt}{\abovecaptionskip}% create gap between rows
  \refstepcounter{subfigure}%
  \raisebox{-\height}{(\thesubfigure)~}% align
  \label{#1}\ignorespaces}
  • Thank you, this solves my basic problem (although I find it a little bit strange that subcaption has no setting for this and now I have to rewrite the code for all my figures...). But one little thing: the labels do not align with the top of the figure, how could this be achieved? – Taunch Feb 1 '17 at 21:29
  • I discovered that \abovecaptionskip it larger outside the subfigure than inside (10pt vs 6pt). In any case, you can adjust the \raisebox in \sidecaption to whatever you think looks good. – John Kormylo Feb 2 '17 at 15:33

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.