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:
- Add
\usepackage{graphicx}to the preamble. - Open a
figureenvironment with a placement option, for example[htp]. - Add
\centering, then\includegraphics[width=0.8\textwidth]{image-file}. - Add
\caption{A descriptive image caption.}. - Add
\label{fig:example}directly after the caption, then close the environment. - 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.








