Documentation/Tables & Figures/How to Crop or Trim Images in LaTeX
Tables & Figures

How to Crop or Trim Images in LaTeX

Exported plots and diagrams often come with excessive whitespace or unwanted borders. Instead of editing the original image file, you can crop directly in LaTeX using the trim and clip options of \includegraphics. This keeps your workflow non-destructive and reproducible. Bibby AI's live preview shows the cropping result immediately, so you can fine-tune the trim values without repeated manual compiles.

Use trim and clip to Crop an Image

The trim option takes four values: {left bottom right top} in points (1 inch = 72pt). You must also add clip to actually remove the trimmed area:

\usepackage{graphicx}

% Syntax: trim={left bottom right top}
\begin{figure}[htbp]
\centering
\includegraphics[
    width=0.7\textwidth,
    trim={20 30 20 10},  % Trim 20pt left, 30pt bottom, 20pt right, 10pt top
    clip                  % REQUIRED — without clip, trim has no visible effect
]{figures/plot-with-whitespace.pdf}
\caption{Performance results (trimmed to remove excess whitespace).}
\label{fig:trimmed}
\end{figure}

% Common units you can use:
% trim=20 30 20 10      — points (default)
% trim=1cm 1.5cm 1cm 0.5cm — centimeters
% trim=0.5in 0.5in 0.5in 0.5in — inches

Use viewport to Show Only a Region of Interest

Instead of specifying what to remove (trim), you can specify what to keep using the viewport option — this is useful when you want to extract a specific region:

\usepackage{graphicx}

% viewport defines the visible rectangle: {left bottom right top}
% Coordinates start from the bottom-left corner of the image
\begin{figure}[htbp]
\centering
\includegraphics[
    width=0.6\textwidth,
    viewport=50 100 400 350,  % Show only this rectangular region
    clip
]{figures/full-dashboard.png}
\caption{Zoomed-in view of the key metrics panel.}
\label{fig:metrics-zoom}
\end{figure}

% This is great for extracting parts of screenshots or large diagrams
\begin{figure}[htbp]
\centering
\includegraphics[
    width=0.5\textwidth,
    viewport=0 0 300 200,
    clip
]{figures/world-map.pdf}
\caption{Regional view of the study area.}
\label{fig:region}
\end{figure}

Auto-Trim Whitespace for PDF Plots

For matplotlib or other plots saved as PDF, you can trim whitespace at export time (best practice) or use \adjustbox for auto-trimming in LaTeX:

% BEST PRACTICE: Trim at export time in Python
% import matplotlib.pyplot as plt
% fig.savefig('plot.pdf', bbox_inches='tight', pad_inches=0.1)

% If you can't re-export, use adjustbox to auto-trim in LaTeX:
\usepackage{adjustbox}

\begin{figure}[htbp]
\centering
\begin{adjustbox}{trim=5mm 5mm 5mm 5mm, clip, max width=0.8\textwidth}
    \includegraphics{figures/old-plot.pdf}
\end{adjustbox}
\caption{Imported figure with whitespace removed.}
\label{fig:old-plot}
\end{figure}

% For a consistent approach across many figures, define a command:
\newcommand{\trimfig}[3][]{%
    \includegraphics[width=#2, trim=10 10 10 10, clip, #1]{#3}%
}
% Usage: \trimfig{0.7\textwidth}{figures/plot.pdf}
% Or with extra options: \trimfig[angle=90]{0.7\textwidth}{figures/plot.pdf}

💡 Tips

  • Always include clip when using trim — without it, the content is shifted but not actually cropped.
  • Use bbox_inches='tight' in matplotlib's savefig() to minimize whitespace at the source — it's more reliable than LaTeX-side trimming.
  • Trim values are relative to the natural size of the image, not the displayed size set by width=.
  • Bibby AI shows trim and crop results live, so you can adjust values interactively without recompiling each time.

Try This in Bibby AI

Write LaTeX faster with AI auto-complete and instant compilation.

Start Writing Free

Related Tutorials

How to Crop or Trim Images in LaTeX | Bibby AI