LaTeX Subfigure: Figures Side by Side

Load subcaption and put a LaTeX subfigure environment for each image inside one figure. Give each a width such as 0.45\linewidth; when the widths add up to less than the line, the images sit side by side, labeled (a), (b) and so on.

LaTeX
\begin{figure}[h]
  \centering
  \begin{subfigure}{0.45\linewidth}
    \includegraphics[width=\linewidth]{example-image-a}
    \caption{Before}
    \label{fig:before}
  \end{subfigure}
  \hfill
  \begin{subfigure}{0.45\linewidth}
    \includegraphics[width=\linewidth]{example-image-b}
    \caption{After}
    \label{fig:after}
  \end{subfigure}
  \caption{Two subfigures with their own captions}
  \label{fig:pair}
\end{figure}
Figure~\ref{fig:pair} shows the change; panel~\subref{fig:after} is the result,
also written as Figure~\ref{fig:after}.
OutputTwo sample images side by side with captions (a) Before and (b) After, a main caption Figure 1, and a sentence referring to Figure 1, panel b and Figure 1b.

Needs \usepackage{graphicx}, \usepackage{subcaption} in the preamble.

Full document you can compile
example.tex
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}[h]
  \centering
  \begin{subfigure}{0.45\linewidth}
    \includegraphics[width=\linewidth]{example-image-a}
    \caption{Before}
    \label{fig:before}
  \end{subfigure}
  \hfill
  \begin{subfigure}{0.45\linewidth}
    \includegraphics[width=\linewidth]{example-image-b}
    \caption{After}
    \label{fig:after}
  \end{subfigure}
  \caption{Two subfigures with their own captions}
  \label{fig:pair}
\end{figure}
Figure~\ref{fig:pair} shows the change; panel~\subref{fig:after} is the result,
also written as Figure~\ref{fig:after}.
\end{document}

How does each LaTeX subfigure get its label?

Each \caption inside a subfigure is numbered (a), (b), (c); the \caption after them is the main figure caption. Put \label after each caption. \ref to a panel prints "1b", and \subref prints only the letter, "b".

Why does a LaTeX subfigure drop to a new row?

Either the widths add up to more than \linewidth, or there is a blank line between the environments, which starts a new paragraph and so a new row. Use \hfill to push two panels to the edges, or a small space such as \quad.

How do you make a grid of images?

Fit as many panels in a row as the widths allow, and leave a blank line where the next row should start. With an empty \caption{}, a panel shows only its letter.

LaTeX
\begin{figure}[h]
  \centering
  \begin{subfigure}{0.3\linewidth}
    \includegraphics[width=\linewidth]{example-image-a}
    \caption{}
  \end{subfigure}
  \begin{subfigure}{0.3\linewidth}
    \includegraphics[width=\linewidth]{example-image-b}
    \caption{}
  \end{subfigure}
  \begin{subfigure}{0.3\linewidth}
    \includegraphics[width=\linewidth]{example-image-c}
    \caption{}
  \end{subfigure}

  \begin{subfigure}{0.3\linewidth}
    \includegraphics[width=\linewidth]{example-image}
    \caption{}
  \end{subfigure}
  \caption{A 3 + 1 grid: a blank line starts a new row}
\end{figure}
OutputThree sample images in a row labeled a, b, c, a fourth image d on a second row, and the main caption.

Needs \usepackage{graphicx}, \usepackage{subcaption} in the preamble.

Full document you can compile
example.tex
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}[h]
  \centering
  \begin{subfigure}{0.3\linewidth}
    \includegraphics[width=\linewidth]{example-image-a}
    \caption{}
  \end{subfigure}
  \begin{subfigure}{0.3\linewidth}
    \includegraphics[width=\linewidth]{example-image-b}
    \caption{}
  \end{subfigure}
  \begin{subfigure}{0.3\linewidth}
    \includegraphics[width=\linewidth]{example-image-c}
    \caption{}
  \end{subfigure}

  \begin{subfigure}{0.3\linewidth}
    \includegraphics[width=\linewidth]{example-image}
    \caption{}
  \end{subfigure}
  \caption{A 3 + 1 grid: a blank line starts a new row}
\end{figure}
\end{document}

Can you put figures side by side without subcaption?

Yes, with two minipage boxes inside one figure. Each caption is then a full figure caption (Figure 1, Figure 2) rather than (a) and (b). Use this when the images are separate figures that just share a row.

LaTeX
\begin{figure}[h]
  \centering
  \begin{minipage}{0.45\linewidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-a}
    \caption{First image}
  \end{minipage}
  \hfill
  \begin{minipage}{0.45\linewidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-b}
    \caption{Second image}
  \end{minipage}
\end{figure}
OutputTwo sample images side by side with separate captions Figure 1: First image and Figure 2: Second image.

Needs \usepackage{graphicx} in the preamble.

Full document you can compile
example.tex
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
  \centering
  \begin{minipage}{0.45\linewidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-a}
    \caption{First image}
  \end{minipage}
  \hfill
  \begin{minipage}{0.45\linewidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-b}
    \caption{Second image}
  \end{minipage}
\end{figure}
\end{document}

Should you use the subfigure or subfig package?

No. The subfigure package is obsolete, and subfig hasn't been updated in years and clashes with hyperref in some setups. subcaption is the maintained choice and also provides subtable for tables side by side.

How do you insert and size each image?

The options of \includegraphics, such as width, crop and rotation, are in the image guide. Inside a subfigure, width=\linewidth fills the panel. For tables in a row, see the tables guide and swap subfigure for subtable. The LaTeX table generator writes the tabular for each panel.

Text drafted with AI from the subcaption documentation; every example compiled with TeX Live 2026; checked by Cem Demir. See the editorial policy.