Skip to main content
v2026.11,858 entries · CC-BY 4.0

LaTeX Figure: Insert an Image, Caption It and Add Subfigures

Insert a figure in LaTeX with graphicx, caption and label it correctly, control float placement and add subfigures with subcaption.

Written and maintained by CASRAI Editorial Board

Last updated

To insert a figure in LaTeX, load the graphicx package in the preamble, then wrap \includegraphics in a figure environment with a \caption and a \label. Put the \label after the \caption, or the reference will print a section number instead of the figure number. For several panels under one number, use the subcaption package. This guide covers all of it, plus the float-placement specifiers and the two failures that cause most questions: a figure that drifts to a later page and a reference that shows the wrong number.

What a figure is used for in research writing

A LaTeX figure is a floating block that holds an image, a caption and a label. The caption is numbered automatically, and the label lets you refer to the figure from the text so the number stays correct when figures are added or moved. Overleaf’s documentation describes the task as three parts: provide the image file, provide the LaTeX code that includes it, and provide additional code or options that treat it as a figure that can be captioned and referenced.

Install or access

Nothing beyond the graphicx package is needed for a single figure. Load it once in the preamble:

\usepackage{graphicx}

If you write in Overleaf, upload the image file to the project first, then reference it by file name in \includegraphics. Overleaf’s page on inserting images (checked 2026-10-29) outlines the same three parts. New to the editor? See what Overleaf is.

Insert a figure in LaTeX: graphicx, figure, caption and label

The steps below build a basic figure:

  1. Add \usepackage{graphicx} to the preamble.
  2. Open a figure environment with a placement option, for example [htp].
  3. Add \centering, then \includegraphics[width=0.8\textwidth]{image-file}.
  4. Add \caption{A descriptive image caption.}.
  5. Add \label{fig:example} directly after the caption, then close the environment.
  6. In the text, refer to it with See Figure~\ref{fig:example}.
\begin{figure}[htp]
  \centering
  \includegraphics[width=0.8\textwidth]{image-file}
  \caption{A descriptive image caption.}
  \label{fig:example}
\end{figure}

Here width=0.8\textwidth sets the image width to 0.8 of the text width. The [htp] option lists the places LaTeX may put the figure: here, at the top of a page, or on a page of floats.

Why the label goes after the caption

The caption is what sets the figure number that \label records. According to the LaTeX Wikibooks chapter on floats (a community-written secondary source, checked 2026-10-29), a \label placed before the \caption, or outside the float, makes \ref show the section number instead. Keep the order caption, then label, both inside the figure environment.

Short captions for the list of figures

The same Wikibooks chapter notes that \caption[short]{long} puts the short text in the list of figures and the long text under the figure.

Float placement specifiers

The optional argument of \begin{figure}[...] lists where LaTeX may put the float. Per the Wikibooks chapter on floats:

Specifier Meaning
h Here, approximately where the figure appears in the source text
t Top of a page
b Bottom of a page
p A separate page of floats
! Overrides LaTeX’s internal limits on float placement
H Place the float here; requires the float package (\usepackage{float})

LaTeX treats these as permissions, not commands, so it may still defer a float to a later page.

Subfigures in LaTeX with subcaption

When one figure has several panels, each with its own sub-caption, use the subcaption package. CTAN describes it as providing facilities analogous to those of the caption package when writing captions for subfigures and the like. CTAN lists version 1.6 dated 2023-08-13 under the LaTeX Project Public License 1.3, and it is distributed with the caption package (ctan.org/pkg/subcaption, checked 2026-10-29).

The form shown in the Wikibooks chapter is:

\usepackage{subcaption}

\begin{figure}
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{image-a}
    \caption{First panel}
    \label{fig:a}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.3\textwidth}
    \includegraphics[width=\textwidth]{image-b}
    \caption{Second panel}
    \label{fig:b}
  \end{subfigure}
  \caption{Both panels together}
  \label{fig:both}
\end{figure}

Each subfigure has its own width, caption and label. The overall caption sits outside the subfigures, and \hfill separates the panels. Because each panel has its own label, you can cite a single panel (\ref{fig:a}) or the whole figure (\ref{fig:both}).

The subcaption manual (subcaption.pdf on CTAN) has sections on \subcaptionbox, \subcaptionblock, \subcaptiongroup, cross-referencing and numbering.

Output and how to read it

The compiled figure shows the image with its numbered caption, and each \ref in the text is replaced by that number. With subfigures, each panel carries its own sub-caption and the overall caption carries the figure number.

Troubleshooting

The figure appears on a later page

Floats may move. Add t or p to the placement list, add ! to relax LaTeX’s limits, or use H with the float package when the figure must sit exactly where it is written.

The reference shows a section number

The \label is before the \caption or outside the figure. Move it directly after the caption.

A journal template conflicts with subcaption

Per the Wikibooks chapter, the subfig package works with journal templates that are incompatible with subcaption. If you are formatting a submission, see manuscript format for journal submission.

Other subfigure packages

Package Status
subcaption On CTAN, version 1.6 (2023-08-13), distributed with the caption package
subfig Listed on CTAN as related (“Figures broken into subfigures”); Wikibooks says it works with journal templates incompatible with subcaption
subfigure Described by the Wikibooks chapter as deprecated

Frequently asked questions

How do I insert a figure in LaTeX?

Load graphicx, then put \includegraphics, \caption and \label, in that order, inside a figure environment, as in the example above.

How do I add subfigures in LaTeX?

Load subcaption and place one subfigure environment per panel inside a single figure, each with a width, caption and label.

Why does my LaTeX figure show the wrong number?

The label is usually before the caption. Put \label after \caption inside the float.

How do I keep a figure exactly where I put it?

Use the H specifier, which needs the float package.

Sources

  • Overleaf documentation, Inserting images, https://docs.overleaf.com/writing-and-editing/inserting-images, checked 2026-10-29.
  • CTAN, subcaption package, https://ctan.org/pkg/subcaption, checked 2026-10-29.
  • Wikibooks (community-written), LaTeX/Floats, Figures and Captions, https://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions, checked 2026-10-29.

Related reading: LaTeX bibliography styles explained, adding citations and a bibliography in Overleaf, collaborative writing in LaTeX and Overleaf.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about LaTeX Figure: Insert an Image, Caption It and Add Subfigures

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.