Figures and Images

Subfigures in LaTeX: Positioning and Grid Layouts

Build subfigures in LaTeX with the subcaption package: set vertical alignment, lay out a 3x2 grid, adjust caption position and reference subfigures.

On this page
  1. Subfigures or minipage?
  2. Load subcaption
  3. A two-image subfigure
  4. Vertical alignment with [t], [b] and [c]
  5. A 3x2 grid layout
  6. Caption position and labels
  7. Refer to subfigures with \subref
  8. Common problems
  9. Summary

To put several images under one figure, with their own (a), (b) and (c) captions, use the subcaption package. Place a subfigure environment for each image inside a figure, set its vertical alignment with [t], [b] or [c], and set its width. For a 3x2 grid (three images across, two rows), give each subfigure about 0.32 of the text width.

Subfigures or minipage?

Both put images side by side, but they work differently.

  • A subfigure gives each image its own sub-caption and label, and it lets you refer to each one with \subref. It was designed for this job.
  • A minipage is a plain box, as described in how to make a text box with minipage and parbox. It can hold an image and a caption, but you handle numbering and labels yourself.

If you want one caption and one figure number for a group of images, use subfigures. For text that sits beside an image, see how to wrap text around an image.

Load subcaption

Load the package in the preamble, along with graphicx for the images:

\usepackage{graphicx}
\usepackage{subcaption}

Older guides use the subfig package or an older subfigure package. The subfigure package is obsolete. subfig and subcaption define overlapping commands, so load only one of them.

A two-image subfigure

\begin{figure}[htbp]
  \centering
  \begin{subfigure}{0.45\textwidth}
    \centering
    \includegraphics[width=\linewidth]{left-image}
    \caption{Before filtering.}
    \label{fig:before}
  \end{subfigure}
  \hfill
  \begin{subfigure}{0.45\textwidth}
    \centering
    \includegraphics[width=\linewidth]{right-image}
    \caption{After filtering.}
    \label{fig:after}
  \end{subfigure}
  \caption{Effect of the filter on a sample image.}
  \label{fig:filter}
\end{figure}

Each sub-caption is numbered (a) and (b). The caption after the subfigures is the figure’s main caption. Inside each subfigure, \linewidth equals the subfigure’s width, so the image fills its box.

Vertical alignment with [t], [b] and [c]

Images in a row often have different heights. The optional argument before the width sets how each subfigure lines up with the row:

  • [t] aligns the top edges.
  • [b] aligns the bottom edges.
  • [c] centres each subfigure vertically.
\begin{subfigure}[t]{0.45\textwidth}
  ...
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\textwidth}
  ...
\end{subfigure}

Set the option explicitly on every subfigure, so the layout doesn’t change when an image is resized.

A 3x2 grid layout

For six images in two rows of three, make each subfigure 0.32 of the text width. Three of them plus two gaps fit on one line. A \\ after the last subfigure in a row starts the next row:

\begin{figure}[htbp]
  \centering
  \begin{subfigure}[t]{0.32\textwidth}
    \centering
    \includegraphics[width=\linewidth]{sample-1}
    \caption{Sample 1.}
    \label{fig:grid-1}
  \end{subfigure}
  \hfill
  \begin{subfigure}[t]{0.32\textwidth}
    \centering
    \includegraphics[width=\linewidth]{sample-2}
    \caption{Sample 2.}
    \label{fig:grid-2}
  \end{subfigure}
  \hfill
  \begin{subfigure}[t]{0.32\textwidth}
    \centering
    \includegraphics[width=\linewidth]{sample-3}
    \caption{Sample 3.}
    \label{fig:grid-3}
  \end{subfigure}
  \\[1em]
  \begin{subfigure}[t]{0.32\textwidth}
    \centering
    \includegraphics[width=\linewidth]{sample-4}
    \caption{Sample 4.}
    \label{fig:grid-4}
  \end{subfigure}
  \hfill
  \begin{subfigure}[t]{0.32\textwidth}
    \centering
    \includegraphics[width=\linewidth]{sample-5}
    \caption{Sample 5.}
    \label{fig:grid-5}
  \end{subfigure}
  \hfill
  \begin{subfigure}[t]{0.32\textwidth}
    \centering
    \includegraphics[width=\linewidth]{sample-6}
    \caption{Sample 6.}
    \label{fig:grid-6}
  \end{subfigure}
  \caption{Six samples in two rows of three.}
  \label{fig:grid}
\end{figure}

For two images across and three rows instead, use widths of 0.48 and add a \\ after every second subfigure.

Caption position and labels

Sub-captions sit below each image by default. To move them above, add this to the preamble:

\captionsetup[subfigure]{position=top}

Put each \label after its \caption inside the subfigure, as shown above. This way the label points to the sub-caption number.

Refer to subfigures with \subref

Use \subref to refer to one subfigure. It prints the sub-label, such as (b). Use \ref for the main figure number:

As Figure~\ref{fig:grid} shows, sample~\subref{fig:grid-2} has the brightest background.

Common problems

  • A row wraps early. The subfigure widths and gaps add up to more than the text width. Reduce the widths, or check that the gaps are small.
  • Package errors about a clash. You loaded subfig and subcaption together, or an old subfigure package. Keep one sub-caption package.
  • Uneven gaps between images. Set [t], [b] or [c] on every subfigure. You can also set the same height with height= and keepaspectratio in \includegraphics, if the images’ proportions allow it.
  • The whole figure jumps to another page. Large figures can move away from the text. The figure placement guide explains how to control this.
  • Sub-captions run long. Long text makes each sub-caption wrap onto several lines. Keep them short, and put detail in the body text.

Summary

Use subcaption, put each image in a subfigure with a width of about 0.32 of the text width for three across, and set [t], [b] or [c] to control alignment. Label each subfigure and refer to it with \subref. For the image basics that go inside each subfigure, see the guide to inserting images in LaTeX.

The complete guide to figures and images

Inserting Images in LaTeX: PDF, PNG and More
Read the guide

Keep exploring

Guides from other topics

All topics →