Tx · LaTeX & TikZ

How to Put Figures Side by Side in LaTeX

Updated 13 October 2026

At a glance

  1. 1. Load subcaption

    Add the subcaption package to your document preamble.

  2. 2. Set each width

    Give each subfigure a width slightly below half the available line width.

  3. 3. Insert each image

    Scale each image to its subfigure's line width and add its own caption if needed.

  4. 4. Separate and label

    Use horizontal fill between the subfigures and place labels after their captions.

To put two images side by side, place them in separate subfigures inside one figure environment. The subcaption package provides a modern way to give each image its own caption and label, while the enclosing figure can have a shared caption.

Use the subcaption package

This complete example uses demonstration images from the mwe package, so it can be compiled as written. In your own document, replace the demo image names with your image files.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{mwe} % provides example-image-a and example-image-b

\begin{document}

\begin{figure}[htbp]
  \centering
  \begin{subfigure}[t]{0.48\linewidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-a}
    \caption{First image}
    \label{fig:first}
  \end{subfigure}\hfill%
  \begin{subfigure}[t]{0.48\linewidth}
    \centering
    \includegraphics[width=\linewidth]{example-image-b}
    \caption{Second image}
    \label{fig:second}
  \end{subfigure}
  \caption{A shared caption for the pair.}
  \label{fig:pair}
\end{figure}

\end{document}

The required packages are graphicx for including images and subcaption for the subfigure environments and captions. The mwe package supplies the example image files; remove it when you use your own images.

The two subfigures are each 0.48\linewidth wide, leaving a small gap for \hfill. Inside a subfigure, \linewidth means the width of that subfigure, so \includegraphics[width=\linewidth]{...} makes the image fit its box without changing its proportions. The [t] option aligns the subfigure boxes at the top.

Each \caption inside a subfigure creates a subcaption. The final \caption belongs to the overall figure. Put each \label after the caption it refers to; you can then refer to the pair with \ref{fig:pair} and to an individual image with its subfigure label.

Adjust the width and spacing

The subfigure widths and the gap must fit within the available line. Two boxes at 0.48\linewidth use 96% of that width, leaving room for the stretchable space from \hfill. If you increase either box, reduce the other or remove the gap. Widths that add up to more than the available line can cause the second image to move below the first or produce an overfull line.

Using \linewidth makes the example adapt to the space available where the figure appears. This is useful in two-column documents: an ordinary figure occupies one column, while figure* generally spans both columns. If you instead use \textwidth for each subfigure, the boxes may be too wide for a single column.

If the images have different aspect ratios, their displayed heights may differ even though their widths match. That is normal. To give them the same maximum height while preserving their proportions, use an option such as \includegraphics[height=4cm,keepaspectratio]{...} for each image. Choose a height that suits the page layout.

When you want only one caption

If the images do not need separate captions, you can use two \includegraphics commands directly in a single figure, placing \hfill between them. Give the enclosing figure one caption and label. Subfigures are useful when readers need to identify or reference the images individually; otherwise, a single caption may be simpler.

Common mistakes

  • Using widths that leave no room for the gap: Two boxes of exactly 0.5\linewidth leave no space for \hfill. Make their combined width slightly less than the available line.
  • Using the wrong reference width: In a two-column layout, \textwidth may be wider than the column. Use \linewidth for widths inside the figure.
  • Leaving a blank line between the subfigures: A blank line starts a new paragraph and may put the second subfigure below the first. Keep the environments in the same paragraph; the % after \hfill in the example also prevents an unwanted line-end space.
  • Loading an outdated subfigure package: Use subcaption for new documents, and do not load it alongside the older subfigure package. Package conflicts can prevent the document from compiling.
  • Putting a label before its caption: A label records the most recently updated counter. Place it after the relevant \caption so references point to the intended figure or subfigure.

References

  1. CTAN: subcaption package
  2. CTAN: mwe package

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.