Crop an image in LaTeX (trim, clip)
\includegraphics[trim=20 10 60 30,clip]{image.png} cuts 20 bp off the left, 10 bp off the bottom, 60 bp off the right and 30 bp off the top. The order is always left, bottom, right, top.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{graphicx}Cut off the edges with trim
The four values are separated by spaces. A number without a unit is in bp (big points, 1/72 inch); other units work as well, for example trim=1cm 0cm 1cm 0cm. clip hides the trimmed parts.
\includegraphics[trim=20 10 60 30,clip]{image.png}Crop and scale
The trim values refer to the natural size of the image, not to the size on the page. A width after them applies to the cropped result: here the remaining part of the image becomes 5 cm wide.
\includegraphics[trim=20 10 60 30,clip,width=5cm]{image.png}Select a region with viewport
viewport names the part to keep instead of the parts to remove. Its four values are the coordinates of the lower left and the upper right corner of the region, measured from the lower left corner of the image.
\includegraphics[viewport=20 10 260 170,clip]{image.png}Pitfalls
- Without
clip, the image is still drawn completely. LaTeX only reserves the smaller space, and the trimmed parts overlap the neighboring text. - For a PNG without a stored resolution, 1 bp is one pixel, because pdfLaTeX assumes 72 pixels per inch. For other files, convert pixels to bp with the resolution of the file.
- Cropping hides a part of the image but does not remove it from the PDF. Crop the file itself when the hidden part must not be passed on.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
graphicx - How-to Resize an image in LaTeX
- How-to Insert an image in LaTeX
- How-to Rotate an image in LaTeX