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}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}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}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}Pitfalls
- For a PNG without a stored resolution, pdfLaTeX assumes 72 pixels per inch. An image of 320 × 200 pixels is then 320 × 200 bp, about 11.3 cm wide.
- An image that is wider than the line sticks out into the right margin, and the log shows Overfull \hbox (263.664pt too wide) in paragraph at lines 3--6.
- Scaling changes the size on the page only. The file is embedded in the PDF in full resolution.
Compiled with pdfLaTeX from TeX Live 2023.