Resize an image in LaTeX (width, height, scale)

Set the size in the optional argument of \includegraphics: width=0.8\textwidth for a width relative to the text block, height=5cm for a fixed height, or scale=0.5 for half the natural size. With only one of width and height, the image keeps its proportions.

Preamble

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

\usepackage{graphicx}

Set the width

\textwidth is the width of the text block and \linewidth the width of the current line, which is smaller inside a column, a minipage or a list. A width relative to one of them still fits when you change the page layout. Absolute lengths such as 6cm work as well.

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

\includegraphics[width=6cm]{image.png}
Result
The compiled example

Fit an image into a box

width and height together stretch the image to exactly that size and distort it. With keepaspectratio, the two values are upper limits: the image becomes as large as possible without exceeding either of them.

\includegraphics[width=5cm,height=2cm,keepaspectratio]{image.png}
Result
The compiled example

Scale by a factor

scale=0.5 halves the natural size of the image. For a PNG or JPG the natural size depends on the pixel count and the resolution stored in the file, so width gives a more predictable result.

\includegraphics[scale=0.5]{image.png}
Result
The compiled example

Shrink only images that are too wide

width=\textwidth also enlarges small images. With \usepackage[export]{adjustbox}, \includegraphics accepts max width: a wider image is scaled down to the limit, a narrower one keeps its size.

Complete document:

\documentclass{article}
\usepackage[export]{adjustbox}
\begin{document}
\includegraphics[max width=\textwidth]{logo.png}

\includegraphics[max width=3cm]{image.png}
\end{document}
Result
The compiled example

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages