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:
Best Answer
\subcaptionbox
is based on\parbox
(and therefore inherits its optional argument "inner-pos") whilesubfigure
is based on theminipage
environment (which offers a different set of optional arguments).\subcaptionbox
is as wide as its contents. (When usingsubfigure
a width has always to be given explicitly since it's a mandatory argument there.)\subcaptionbox
the caption will be placed above or below its contents, depending on theposition=
option. When usingsubfigure
the caption will be placed where\caption
is.\subcaptionbox
the baseline of the resulting\parbox
will be identical with the baseline of the 1st caption line. When usingsubfigure
the baseline is dependent on the content (and the optional alignment parameter "outer-pos" which isn't available for\subcaptionbox
).