Figures and Images in LaTeX

Adding images to a LaTeX document is straightforward once you understand the float system. This guide covers how to include images, control their size and position, add captions, create side-by-side subfigures, and cross-reference figures in your text.

The graphicx Package

Always load graphicx in your preamble. It provides the \includegraphics command that handles PNG, JPEG, PDF, and EPS formats.

\usepackage{graphicx}          % in preamble
\graphicspath{{./images/}}     % optional: set image folder

\begin{figure}[htbp]
  \centering
  \includegraphics[width=0.7\textwidth]{diagram}
  \caption{A descriptive caption goes here.}
  \label{fig:diagram}
\end{figure}

% Reference anywhere in text:
As shown in Figure~\ref{fig:diagram}, the system...

Sizing Options

OptionEffect
width=0.8\textwidth80% of the text column width — most common
width=\columnwidthFull column width (for two-column documents)
width=5cmAbsolute width of 5 centimetres
height=4cmFixed height, width scales proportionally
scale=0.550% of the original image size
angle=90Rotate image 90° counter-clockwise

Always use relative units like \textwidth or \columnwidth instead of absolute centimetres — this keeps your figures correctly sized if you ever change the page margins.

Float Placement Specifiers

The optional argument to \begin{figure} controls where LaTeX is allowed to place the float. LaTeX tries each option in order.

hHere — at the approximate location in the source (not always possible)
tTop — at the top of the current or next page
bBottom — at the bottom of a page
pPage — on a dedicated floats-only page
HExactly here — forces placement (requires float package)
!Override LaTeX's internal float placement restrictions

Recommendation: use [htbp] for most figures. Avoid h alone — LaTeX often ignores it and produces a warning.

Side-by-Side Figures with subcaption

Use the subcaption package to place multiple figures side by side with individual sub-captions and a shared main caption.

\usepackage{subcaption}   % in preamble

\begin{figure}[htbp]
  \centering
  \begin{subfigure}[b]{0.45\textwidth}
    \includegraphics[width=\textwidth]{before}
    \caption{Before processing}
    \label{fig:before}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.45\textwidth}
    \includegraphics[width=\textwidth]{after}
    \caption{After processing}
    \label{fig:after}
  \end{subfigure}
  \caption{Comparison of input and output images.}
  \label{fig:comparison}
\end{figure}

% Reference individual sub-figures:
See Figure~\ref{fig:before} and Figure~\ref{fig:after}.

Wrapping Text Around a Figure

For smaller figures that should sit inline with text, use the wrapfig package.

\usepackage{wrapfig}

\begin{wrapfigure}{r}{0.35\textwidth}  % r = right side
  \centering
  \includegraphics[width=0.33\textwidth]{logo}
  \caption{Company logo}
\end{wrapfigure}

The logo is displayed to the right of this paragraph.
Text flows naturally around it. Make sure there is enough
text to fill the space beside the figure, otherwise the
layout will look awkward.

Common Mistakes

  • Including the file extension in \includegraphics — LaTeX picks the best format automatically: use {diagram} not {diagram.png}
  • Using absolute pixel sizes like width=800px — use \textwidth based fractions instead
  • Placing \caption after \label — always label after the caption: \caption{...} then \label{...}
  • Forgetting \centering inside the figure — without it the image aligns left
  • Using .bmp files — convert to .png or .pdf for better quality and smaller file size

Try figures in the editor

Use the wrapfig or subcaption examples directly in Skozin's editor.

Start Writing

Continue Learning