[Tex/LaTex] Controlling subfigure captions and subfigure placement

graphicssubcaptionsubfigsubfloats

The following code

\documentclass{article}
\usepackage{graphicx, caption, subcaption}
\begin{document}
\begin{figure}[h]
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[width=\textwidth]{image1_example}
\caption{The rectangle is a complicated geometrical figure that has 4 edges and 4 vertices while a star is an even more complex geometrical figure}
\end{subfigure}
\begin{subfigure}[b]{0.4\textwidth}
\includegraphics[width=\textwidth]{image2_example}
\caption{A simple circle and a spiral}
\end{subfigure}
\caption{Geometrical figures}
\end{figure}
\end{document}


produces the following output

1. The more verbose caption for subfigure a) produces an asymmetric
placement of the two subfigures.

2. It would be nicer if there would be more horizontal space between the
two subfigures.

Is it possible to control these features?

The optional argument for the subfigure environment provides the placement of the sub-caption anchor. This is used to align the sub-captions vertically. Here is a visual:

\documentclass{article}

\usepackage{graphicx,subcaption}

\begin{document}

\begin{figure}
\centering
\texttt{subfigure} with \texttt{[t]}op alignment

\medskip

\begin{subfigure}[t]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}
\begin{subfigure}[t]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\begin{subfigure}[t]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-c}
\caption{This is a sub-caption. This is a sub-caption.}
\end{subfigure}

\bigskip\hrulefill\bigskip

\texttt{subfigure} with \texttt{[c]}entre alignment (default)

\medskip

\begin{subfigure}{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}
\begin{subfigure}{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\begin{subfigure}{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-c}
\caption{This is a sub-caption. This is a sub-caption.}
\end{subfigure}

\bigskip\hrulefill\bigskip

\texttt{subfigure} with \texttt{[b]}ottom alignment

\medskip

\begin{subfigure}[b]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}
\begin{subfigure}[b]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\begin{subfigure}[b]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-c}
\caption{This is a sub-caption. This is a sub-caption.}
\end{subfigure}
\end{figure}

\end{document}


So I'd use a [t]op alignment. Additionally, you can spread out the figures using a number of options.

\documentclass{article}

\usepackage{graphicx,subcaption}
\usepackage[margin=1cm,showframe]{geometry}% Just for this example

\begin{document}

\begin{figure}
\centering

\medskip

\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}

\bigskip\hrulefill\bigskip

\medskip

\mbox{}\hfill
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\hfill
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\hfill\mbox{}

\bigskip\hrulefill\bigskip

\medskip

\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\hfill
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}

\end{figure}

\end{document}


If your images have different vertical heights and you want to align those as well, you can raise content into place; the default alignment of images would be at the baseline:

\documentclass{article}

\usepackage{graphicx,subcaption}
\newsavebox{\imagebox}

\begin{document}

\begin{figure}
\centering

Default

\medskip

\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth,height=75pt]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth,height=5pc]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}

\bigskip\hrulefill\bigskip

\verb|\raisebox| to vertical top

\medskip

% Store largest image in a box
\savebox{\imagebox}{\includegraphics[width=.2\linewidth,height=75pt]{example-image-a}}%
\begin{subfigure}[t]{.4\linewidth}
\centering\usebox{\imagebox}% Place largest image
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\begin{subfigure}[t]{.4\linewidth}
\centering\raisebox{\dimexpr\ht\imagebox-\height}{% Raise smaller image into place
\includegraphics[width=.5\linewidth,height=5pc]{example-image-b}}%
\caption{This is a sub-caption.}
\end{subfigure}

\bigskip\hrulefill\bigskip

\verb|\raisebox| to vertical centre

\medskip

% Store largest image in a box
\savebox{\imagebox}{\includegraphics[width=.2\linewidth,height=75pt]{example-image-a}}%
\begin{subfigure}[t]{.4\linewidth}
\centering\usebox{\imagebox}% Place largest image
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}