Crop an image in LaTeX
In this tutorial, I will show you how to crop while inserting an image in LaTeX.
First of all, you need to load the graphicx
package. This package provides you a trim
and clip
option, by which you can crop the image. The syntax is:
\includegraphics[trim={<left> <lower> <right> <upper>},clip]{<image-file>}
Here, the clip
option is mandatory otherwise the process will not work. You can enter any unit value available in LaTeX in place of <left>
, <lower>
, <right>
, and <upper>
, the image will be cropped as this value.
\documentclass{article} \usepackage{graphicx} \begin{document} \section{Original image} \begin{figure}[h] \centering \includegraphics[width=0.5\textwidth]{example-image} \caption{Original image} \end{figure} \section{Cropped image} \begin{figure}[h] \centering % Here trim={left=0.7cm lower=1.5cm right=2cm upper=3cm} \includegraphics[trim=0.7cm 1.5cm 2cm 3cm, clip,width=0.5\textwidth]{example-image} \caption{Cropped image} \end{figure} \end{document}
Output:
If you don’t mention the unit then this will progress with the default unit’s big points (bp
).
Crop image based on \width and \height
In order to crop an image based on the image width or height, you have to include the adjustbox
package. This package allows access to \width
and \height
.
In this case, you have to insert the image with this
\adjincludegraphics[trim={<left> <lower> <right> <upper>},clip]{<image-file>}
let’s see an example.
\documentclass{article} \usepackage{adjustbox} \begin{document} \section{Cropped image from bottom} \begin{figure}[h] \centering % Here trimming 50% of the height from bottom \adjincludegraphics[width=.5\textwidth,trim={0 {.5\height} 0 0},clip]{example-image} \caption{trim 50 \% of the height from bottom} \end{figure} \section{Cropped image from left} \begin{figure}[h] \centering % Here trimming 50% of the width from left \adjincludegraphics[height=.5\textwidth,trim={{.5\width} 0 0 0},clip]{example-image} \caption{trim 50 \% of the width from left} \end{figure} \end{document}
Output:
Leave a Reply