Figures and Images: Including, Sizing, and Captioning
~8 min read
By the end of this lesson you can insert an image, scale it, give it a caption and label, position it, and refer to it by number. Load graphicx, then use \includegraphics inside a figure environment.
Loading graphicx and inserting an image
Add \usepackage{graphicx} to the preamble, then place the image with \includegraphics. Upload the image file into your project so LaTeX can find it.
\usepackage{graphicx} % in the preamble
% ...
\includegraphics[width=0.8\linewidth]{diagram.png}Sizing options
| Option | Effect |
|---|---|
| width=0.8\linewidth | Scale to 80% of the text width |
| width=5cm | Fixed width of 5 cm |
| height=4cm | Fixed height |
| scale=0.5 | Scale to 50% of natural size |
| angle=90 | Rotate 90 degrees |
The figure environment: captions and labels
Wrap the image in a figure environment to add a numbered caption and a label you can reference. \centering centers it.
\begin{figure}[ht]
\centering
\includegraphics[width=0.8\linewidth]{diagram.png}
\caption{System architecture overview.}
\label{fig:arch}
\end{figure}
As shown in Figure~\ref{fig:arch}, the system has three layers.The ~ in Figure~\ref{...} is a non-breaking space — it keeps “Figure” and the number together on the same line.
Placement: where figures land
The optional [ht] is a placement hint — LaTeX floats figures to a convenient spot. Common specifiers:
h— “here”, approximately where writtent— top of a pageb— bottom of a pagep— a dedicated page of floats!— try harder to honor your request (e.g.[!ht])
For an image that must appear exactly where written, load \usepackage{float} and use [H].
Supported formats
pdflatex accepts .png, .jpg, and .pdf. Vector graphics (PDF) stay crisp at any size — prefer them for diagrams and plots.
Frequently asked questions
My image does not appear — why?
Check that the file is uploaded to the project, the filename matches exactly (case-sensitive), and graphicx is loaded. The LetX file browser shows what is available to include.
How do I put two images side by side?
Use two \includegraphics inside one figure, or the subcaption package with subfigure environments for individually captioned panels.
How do I force a figure to stay in place?
Load \usepackage{float} and use the [H] specifier: \begin{figure}[H]. This disables floating for that figure.