7

I was recently searching for a way to place subfigures into one overall figure. As I found out, today we should make use of the subcaption package rather than usig subfig or something else.

However, as googling I found two approaches which seems for me to do the same. For this here is my complete MWE:

 \documentclass[]{article}
 \usepackage{mwe}
 \usepackage{subcaption}
 \begin{document}
 \blindtext


 %%%SUBCAPTIONBOX->
 \begin{figure}[h!]
 \centering
 \subcaptionbox{$n = 10$ steps\label{cw_10}}{%
 \includegraphics[width=.48\linewidth]{example-image-a}%
 }\hfill
 \subcaptionbox{$n = 25$ steps\label{cw_25}}{%
 \includegraphics[width=.48\linewidth]{example-image-a}%
 }
 \caption{A figure with two subfigures using SUBCAPTION}
 \label{TS}
 \end{figure}
 %%%<-SUBCAPTIONBOX

 %%%SUBFIGURE->
 \begin{figure}[h!]
 \begin{subfigure}[b]{.45\linewidth}
 \centering
 \includegraphics[width=1\linewidth]{example-image-a}%
 \caption{$n = 10$ steps}
 \label{cw_10}
 \end{subfigure}%
 \hfill
 \begin{subfigure}[b]{.45\linewidth}
 \centering
 \includegraphics[width=1\linewidth]{example-image-a}%
 \subcaption{$n = 25$ steps}
 \label{cw_25}
 \end{subfigure}
 \caption{A figure with two subfigures using SUBFIGURE}
 \label{TS}
 \end{figure}
 %%%<-SUBFIGURE
 \blindtext

 \end{document}

First, I am using a method with subcaptionbox, then with subfigure-environment. Which one is better or is some Approach 'wrong'?

My Code result in this Picture, I did not see any difference:

enter image description here

3
  • I took the liberty to edit the title of your question. I hope this reflects the contents of your actual question a bit better.
    – leandriis
    Commented Aug 22, 2019 at 18:58
  • The subcaption manual contains the following statement: "A different way of setting sub-figures is offered by the \subcaptionbox command [...]" So I'd say both methods can be used equally. A difference between the two however is, that with subfigure you secify two widths, the width of the subfigure and the width of the image, while subcaptionbox only needs the width of the image.
    – leandriis
    Commented Aug 22, 2019 at 19:01
  • 1
    Off topic, Since \subcaption in a figure is the same as \caption in a subfigure, shouldn't \subcaption in a subfigure produce a subsubcaption? Commented Aug 23, 2019 at 3:59

1 Answer 1

7
  • The \subcaptionbox is based on \parbox (and therefore inherits its optional argument "inner-pos") while subfigure is based on the minipage environment (which offers a different set of optional arguments).
  • If no width is given, the \subcaptionbox is as wide as its contents. (When using subfigure a width has always to be given explicitly since it's a mandatory argument there.)
  • When using \subcaptionbox the caption will be placed above or below its contents, depending on the position= option. When using subfigure the caption will be placed where \caption is.
  • When using \subcaptionbox the baseline of the resulting \parbox will be identical with the baseline of the 1st caption line. When using subfigure the baseline is dependent on the content (and the optional alignment parameter "outer-pos" which isn't available for \subcaptionbox).

You must log in to answer this question.

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