2

I am trying to have multiple subfigures in rows with their respective subcation on the left side of them. I found a useful answer on the LaTeX forums using \parbox, but the subcaptions are not vertically centered, even though I put c as the position parameter. I guess it is because the first subcaption-parbox is not the same height dimension as the graphics-parbox. How can I achieve that?

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}

\begin{document}


\begin{figure}
\captionsetup[subfigure]{slc=off,margin={1cm,0cm}}
  \parbox[m]{0.4\textwidth}{\subcaption{A subfigure}}
  \parbox[b]{0.5\textwidth}{\includegraphics[width=\hsize]{image1}}\\
  \parbox[m]{0.4\textwidth}{\subcaption{Another subfigure}}
  \parbox[b]{0.5\textwidth}{\includegraphics[width=\hsize]{image3}}\\
  \parbox[m]{0.4\textwidth}{\subcaption{A third subfigure}}
  \parbox[b]{0.5\textwidth}{\includegraphics[width=\hsize]{image3}}\\
  \caption{A collection of subfigures}
\end{figure}

\end{document}

I am also open for other suggestions that doesn't include \parbox.

Thanks in advance :)

1
  • My guess is that the floatrow package can answer your question. Take a look at its manual pages 68 onward. I will see if I can make a MWE using that package a bit later on.
    – alchemist
    Feb 11 at 12:30

2 Answers 2

2

The middle alignment should work if you want the middle alignment but you would also need to adjust a baseline of each image for the top or the bottom alignments.

Therefore, I would additionally load adjustbox package with an extra optional argument valign, which controls baselines--make sure you add package option [export].

Optional justification=... of \captionsetup controls horizontal alignment of captions; it accepts raggedright, raggedleft, or centering among of others.

Here's slightly changed code:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage[export]{adjustbox}

\usepackage{xcolor}


\begin{document}
\begin{figure}[tbh]
  \setkeys{Gin}{width=0.5\linewidth}
  \captionsetup{position=bottom,skip=15pt}
  \captionsetup[subfigure]{
    justification=raggedright,
    singlelinecheck=no,
    format=hang,
    belowskip=0pt,
    aboveskip=0pt,
    %margin={1cm,0cm},
  }
  \centering
  \begin{subcaptiongroup}
    \parbox[t]{0.4\textwidth}{\caption{A subfigure}}%
    \hspace{1em}%
    \includegraphics[valign=T]{image1}

    \bigskip
    
    \parbox{0.4\textwidth}{\caption{Another subfigure. Another subfigure. Another subfigure}}%
    \hspace{1em}%
    \includegraphics[valign=c]{image3}
    
    \bigskip

    \parbox[b]{0.4\textwidth}{\caption{A third subfigure}}%
    \hspace{1em}%
    \includegraphics[valign=B]{image3}
    \par
  \end{subcaptiongroup}
  \caption{A collection of subfigures}
\end{figure}
\end{document}

enter image description here

6
  • what about the vertical centering of all captions? In your answer only the middle one is vertically centered.
    – alchemist
    Feb 11 at 13:40
  • I know, it's just for demonstration if OP would like to compare code corresponding to each case.
    – Celdor
    Feb 11 at 13:43
  • Ah .. check! Understood
    – alchemist
    Feb 11 at 13:47
  • My LaTeX is not happy about the "subcaptiongroup" environment, I am not sure where you got that from, and I am not sure what the "\setkeys{Gin}{width=\linewidth}" does. Regardless, it works without it, thank you, and the middle example is perfect. Thank you Feb 11 at 14:05
  • subcaptiongroup merely affect regular \caption labels as if \subcaption was used. Other than that, it does nothing! I don't know the reason of your issues; it might be worth looking at the log. Because your layout is heavily customised with parboxes, I thought it might be easier to apply regular macros inside subcaptiongroup. This is a legit environment (see section 4 of documentation).
    – Celdor
    Feb 11 at 14:12
3

This code should do what you are looking for:

\documentclass[11pt]{article}

\usepackage[demo]{graphicx}
\usepackage{subcaption}
\captionsetup[subfigure]{justification=centerlast}

\usepackage{floatrow}
\floatsetup[subfigure]{style=BOXED,capbesideposition={left,center}} % change style to style=plain to remove the boxes

\begin{document}
    
    \begin{figure}
            \ffigbox
            {
            \begin{subfloatrow}
                \fcapside[\FBwidth]{\caption{A subfigure}}{\includegraphics[width=0.45\textwidth]{example=image-a.png}}
            \end{subfloatrow}   
            \begin{subfloatrow}
                \fcapside[\FBwidth]{\caption{A subfigure}}{\includegraphics[width=0.45\textwidth]{example=image-a.png}}
            \end{subfloatrow}
            \begin{subfloatrow}
                \fcapside[\FBwidth]{\caption{A subfigure}}{\includegraphics[width=0.45\textwidth]{example=image-a.png}}
            \end{subfloatrow}
            }
            {\caption{A collection of subfigures}}
    \end{figure}

\end{document}

caption beside figure

1
  • Thanks for your response. I didn't specify this in my question, but I have other subfigure environments which layout I am happy about. This was only one figure that I wanted to have this specific layout. I found a way to hardcode this in by adding a height and inner-position parameter in the parbox command. Feb 11 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .