Site icon texblog

Crop figures with includegraphics

Imagine having a beautiful picture, but the subject is very small or not centered. What if you want to place several graphs side-by-side with subfig, but all or some of the graphs have a white border taking up a lot of space.

So how to trim pictures and eliminate unwanted margins of graphs?

The graphics bundle provides a way to crop an image using the trim, clip options of the includegraphics command.

\usepackage{graphicx}
...
\begin{figure}[htbp]
	\begin{center}
		\includegraphics[trim=left bottom right top, clip]{file}
	\caption{default}
	\label{default}
	\end{center}
\end{figure}

Unless you know exactly how much to crop, you will probably have to try a few times, until you get the numbers right. Make sure you don’t forget clip, since trim alone won’t work. The default units are big points (bp). However, any unit available in LaTeX can be used. See here for more information on units.

Finally, using negative values adds white space to a figure, doing exactly the opposite of cropping.

The graphics bundle user guide has more details and a comprehensive list of options available.

Here is an example:

\documentclass[11pt]{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h!t]
	\begin{center}
	\includegraphics[width=\textwidth]{crab}
	\end{center}
	\label{fig:orig}
\end{figure}
\begin{figure}[h!b]
	\begin{center}
	\includegraphics[trim=1200 400 1500 1500,clip,width=\textwidth]{crab}
	\end{center}
	\label{fig:crop}
\end{figure}
\end{document}

Original and includegraphics trimmed figure.

Exit mobile version