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}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.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}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}Pitfalls
- A wrong file name or path stops with File `imgae' not found. Upper and lower case count on Linux and on most servers, so
Image.PNGandimage.pngare different files there. - An SVG file stops with Unknown graphics extension: .svg.
\usepackage[draft]{graphicx}replaces every image with a frame of the same size that shows the file name. Long documents compile faster this way while you write.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
graphicx - How-to Resize an image in LaTeX
- How-to Figure caption and label in LaTeX
- How-to Set the image folder in LaTeX
- Error File `imgae' not found