The graphicx package

Includes image files with \includegraphics and sets their size, rotation and cropping through options such as width, angle and trim.

Loading the package

\usepackage{graphicx}

LaTeX has no command for images without a package. graphicx provides \includegraphics[options]{file}. With pdfLaTeX the file can be a PNG, a JPG or a PDF; an SVG has to be converted to PDF first.

\includegraphics produces a box that behaves like one large letter. It does not centre the image, add a caption or let it float; for that, put it in a figure environment with \centering and \caption.

The package also scales and rotates text and other material: \rotatebox, \scalebox and \resizebox.

Main commands

\includegraphics[width=0.8\textwidth]{image.png}Image at 80 % of the text width; the height follows from the aspect ratio.
height=4cm, keepaspectratioWith width and height together, keepaspectratio fits the image into the box instead of distorting it.
scale=0.5Half the natural size of the image.
angle=90Rotates the image by 90° counterclockwise.
trim=10 20 30 40, clipCuts off 10, 20, 30 and 40 bp at the left, bottom, right and top.
page=2Selects a page of a PDF file with several pages.
\graphicspath{{images/}}Folder in which LaTeX also looks for image files.
\resizebox{\textwidth}{!}{...}Scales any content, for example a table, to the text width; ! keeps the proportions.

Complete example

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[ht]
  \centering
  \includegraphics[width=0.6\textwidth]{image.png}
  \caption{An image at 60\,\% of the text width.}
  \label{fig:example}
\end{figure}

Inside a line: \includegraphics[height=1.5ex]{logo.png}.
Rotated: \includegraphics[width=2cm, angle=90]{image.png}.
Cropped: \includegraphics[width=2cm, trim=40 20 40 20, clip]{image.png}.
A page of a PDF: \includegraphics[page=1, width=3cm]{figure.pdf}.
\end{document}
Result
The compiled example

Compiled with pdfLaTeX from TeX Live 2023.

Pitfalls

Related pages