Insert an image in LaTeX (includegraphics)

Load the graphicx package and write \includegraphics[width=0.5\textwidth]{image.png}. For a caption and a number, put the command into a figure environment.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{graphicx}

Load graphicx and include the file

The argument in braces is the file name, relative to the folder of the main .tex file. width=0.5\textwidth scales the image to half the width of the text block; without it the image appears in its natural size.

Complete document:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
Text before the image.

\includegraphics[width=0.5\textwidth]{image.png}

Text after the image.
\end{document}
Result
The compiled example

Add a caption and a number

The figure environment is a float: LaTeX moves it to a place where it fits and numbers it. \centering centers the image, \caption prints the text below it, and \label gives the figure a name for \ref.

\begin{figure}
\centering
\includegraphics[width=0.5\textwidth]{image.png}
\caption{The measurement setup}
\label{fig:setup}
\end{figure}

Figure~\ref{fig:setup} shows the setup.
Result
The compiled example

Use a supported file format

pdfLaTeX reads PDF, PNG and JPG files. Use PDF for vector graphics such as plots and diagrams, PNG for screenshots and JPG for photos. Convert EPS and SVG files to PDF first. A PDF file is included like an image; page=2 selects a page other than the first.

\includegraphics[width=0.4\textwidth]{figure.pdf}
Result
The compiled example

Leave out the file extension

Without an extension, LaTeX tries .pdf, .png and .jpg in this order and takes the first file it finds. You can then replace a PNG with a PDF of the same name without changing the document.

\includegraphics[width=0.5\textwidth]{image}
Result
The compiled example

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages