Tx · LaTeX & TikZ

How to Put One Figure Under Another in LaTeX

Published By the 9to5Science editorial team

At a glance

  1. 1. Load graphicx

    Include the graphicx package so LaTeX can insert image files.

  2. 2. Insert both images

    Place two includegraphics commands in one figure environment, with a paragraph break between them.

  3. 3. Set their size

    Give each image a width that fits the text area, leaving room for any vertical gap.

  4. 4. Add one caption

    Use a single caption for the pair, or use separate figure environments if they need independent captions.

To place one image directly under another in LaTeX, insert both images in the same figure environment and separate them with a paragraph break. This makes them a single float with one caption and number. If you instead mean two separately numbered figures, use separate figure environments and account for LaTeX’s float placement rules.

Stack two images in one figure

Load graphicx and use \includegraphics once for each image. A paragraph break (\par) separates the images vertically. You can add a small amount of vertical space with \medskip or \vspace{...} if needed.

Here is a complete example that uses sample images supplied by the mwe package, so it can be compiled without external image files:

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

\begin{document}

\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.7\linewidth]{example-image-a}\par
  \medskip
  \includegraphics[width=0.7\linewidth]{example-image-b}
  \caption{Two images arranged vertically.}
  \label{fig:stacked-images}
\end{figure}

Figure~\ref{fig:stacked-images} contains both images.

\end{document}

Replace example-image-a and example-image-b with your image file names, omitting the extension if LaTeX can determine it. The graphicx package provides \includegraphics; mwe is included here only to provide the sample image files. The width 0.7\linewidth makes each image 70% of the available line width. Adjust it to suit your layout.

Why the paragraph break matters

Two consecutive \includegraphics commands can be treated as material on the same line. If their combined width is too large, they may run together or cause an overfull line. Adding \par ends the line explicitly, putting the second image on the next line. The \centering declaration centers both images within the figure.

You can control the gap between them. \medskip adds a standard moderate vertical space; for a precise gap, use a length such as \vspace{8mm}. For example:

\includegraphics[width=0.6\linewidth]{top-image}\par
\vspace{8mm}
\includegraphics[width=0.6\linewidth]{bottom-image}

The image files must be available to LaTeX, usually in the same folder as the .tex file or in a folder specified by their paths.

If each image needs its own caption

A single figure environment normally gives the pair one figure number and one caption. For separately numbered captions, use two figure environments. Since each is a float, LaTeX can move them independently, so they are not guaranteed to remain directly one after the other.

If you need two captions within one numbered figure, use a subfigure package such as subcaption. That keeps the images together as one float while allowing each image to have a subcaption; it does not create two independently numbered main figures.

Common mistakes

  • Expecting a float to stay exactly where it appears in the source. The [htbp] option suggests placement here, at the top, at the bottom, or on a float page. It does not force an exact position. LaTeX may move the entire stack to improve page layout.
  • Using widths that are too large. Each image must fit within the text area. With vertical stacking, each image can be close to \linewidth; with side-by-side images, their widths plus the gap must fit together.
  • Forgetting the paragraph break. Put \par between the image commands so the second starts below the first.
  • Using separate floats when the images must stay together. Keep them in one figure environment if they should move and be captioned as a unit.
  • Writing \\ as a general-purpose vertical separator. \\ is a line-break command and can behave poorly in this context. A paragraph break with \par is the straightforward choice.

If the images must not float away from the source location, consider inserting them outside a figure environment. You would then need another way to provide a caption and figure number, so for most documents a single float containing both images is the simplest approach.

References

  1. The LaTeX Graphics Companion, Second Edition, Michel Goossens, Sebastian Rahtz, and Frank Mittelbach
  2. The graphicx package on CTAN

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