10

The following code

\documentclass{article}
\usepackage{graphicx, caption, subcaption}
\begin{document}
  This article is about geometrical figures.
  \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

enter image description here

  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?

18

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:

enter image description here

\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.

enter image description here

\documentclass{article}

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

\begin{document}

\begin{figure}
  \centering

  Fixed separation using \verb|\quad| (or \verb|\qquad|, or \verb|\hspace|)

  \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}\quad
  \begin{subfigure}[t]{.4\linewidth}
    \centering\includegraphics[width=.5\linewidth]{example-image-b}
    \caption{This is a sub-caption.}
  \end{subfigure}

  \bigskip\hrulefill\bigskip

  Even spread via \verb|\hfill|

  \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

  Full spread via \verb|\hfill|

  \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:

enter image description here

\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}
  \end{subfigure}\qquad
  \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}
  \end{subfigure}\qquad
  \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}
  \end{subfigure}\qquad
  \begin{subfigure}[t]{.4\linewidth}
    \centering\raisebox{\dimexpr.5\ht\imagebox-.5\height}{% Raise smaller image into place
      \includegraphics[width=.5\linewidth,height=5pc]{example-image-b}}%
    \caption{This is a sub-caption.}
  \end{subfigure}

\end{figure}

\end{document}
5
  • Use the subfigure option [t] instead of [b].

  • To add some horizontal space between the figures, put \quad, \qquad, \hfill or some \hspace command between the subfigure environments.

.

\documentclass{article}
\usepackage{graphicx, caption, subcaption}
\begin{document}
  This article is about geometrical figures.
  \begin{figure}
    \begin{subfigure}[t]{0.4\textwidth}
      \includegraphics[width=\textwidth]{example-image-a}
      \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}
    \hfill
    \begin{subfigure}[t]{0.35\textwidth}
      \includegraphics[width=\textwidth]{example-image-b}
      \caption{A simple circle and a spiral}
    \end{subfigure}
    \caption{Geometrical figures}
  \end{figure}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.