[Tex/LaTex] the difference between subfigure and subcaptionbox both from package subcaption

captionsfloatsgraphicssubcaptionsubfloats

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

Best Answer

  • 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).