TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've caught wind of a trick for trimming/cropping images in LaTeX. I know I can use the trim or viewport option of includegraphics to crop an image as described here and here. Determining what coordinates to use with trim is very time consuming though. This answer mentions the overpic package and suggests its grid can help with determining coordinates. I've gotten this to work wonderfully with Tikz by setting the overpic units to 1mm (Tikz defaults to 1cm I think), but I can't get it to work with a resized image:

    \title{Zoomed Image}

\begin{frame}{With Grid}

        \includegraphics[trim=120 0 0 0,clip,height=0.75\paperheight]{standardWheel}


I set the units of overpic to be one big point (the default units for includegraphics according to this) but it's clear that the grid numbers don't match the crop numbers - according to the grid, trimming 120 off the left side should remove half the wheel. It barely removes anything from the left side. I read online somewhere that this probably doesn't work because I resized the image with height=0.75\paperheight, but it's hard to figure out without resizing because this image is huge. Does anyone know how to get the grid numbers to match the trim numbers for a resized image (I've resized both images the same way).

With Grid Crop


This post on LaTeX community shows that it works well if no resizing is done, but warns that resizing renders it useless.

As a side note, I'm compiling with pdflatex, which reports that it is

pdfTeX using libpoppler 3.141592-1.40.3-2.2 (Web2C 7.5.6)

and I unfortunately am not able to perform installations/updates on this machine.

share|improve this question
up vote 4 down vote accepted

When you trim the image the scaling will change, i.e., the height=0.75\paperheight will resize a different image and hence the x and y scales will change. Effectively you have translated the x-y axes to a different set of plot co-ordinates. I think you will need to calculate the scaling factors and incorporate them into your code, based on some constraints, which you will need to define. Also it appears that beamer does a bit of scaling as well or interferes with overpic and possibly both. (Try the example in article and beamer and you will see the difference).

enter image description here

I personally find it easier to work with a key value interface as the trimming value sequence is anti-intuitive for me. The original author of graphicx, besides having an IQ of in excess of 180 was used to program Postcript with its short cryptic commands, the rest of us need some better mnemonics. Here is a MWE doing this and illustrate the point I raised in my opening paragraph. The code provides means to have a key value interface with pgf and also measure the image. You will still need to incorporate a scaling factor to each values to suit your requirements.

    \title{Zoomed Image}
\pgfkeys{/combo/.is family}
  left/.store in=\left@c,
  right/.store in=\right@c,
  right/.default =99,
  top/.store in=\top@c,
  bottom/.store in= \bottom@c,
      \pgfkeys{/combo #1}
        \includegraphics[trim=##1 ##2 ##3 ##4,clip,height=0.3\textheight]{cardtrick}
   % create and save the box
  % \centering\usebox{\Image}\
      The height of the image (#1) is : \the\imageh\\
     The width of the  image (#1) is : \the\imagew\\
     The depth of the  image (#1) is : \the\imaged\\}

The original image is at cardtrick if you want to experiment with the same image that I have used. Ultimately is always best to rather manipulate images with an external editing program such as gimp. Journal editors are not too happy with authors including additional macros.

share|improve this answer
You and your fantastic image choices!... :) – percusse Mar 18 '12 at 0:47
@percusse It makes boring code more interesting:) – Yiannis Lazarides Mar 18 '12 at 12:36
it might sound silly, but using the right tool for the right job hadn't even occurred to me. i'll eventually be dealing with eps so i'm going to start with a vector graphics editor like inkscape (unless you have a better suggestion). for the future, do you think i could stick you code in a .sty file so i don't have to write it over and over? i presume i'd want to take out \makeatletter and \makeatother. – aeroNotAuto Mar 20 '12 at 4:08
@asia1281 It's always better to make a .sty file and polish the code a bit as well. – Yiannis Lazarides Mar 20 '12 at 5:06

running your example with current texlive I get:

enter image description here

share|improve this answer
i'm not familiar with texlive; a quick google makes it sound like a distribution. is that all it is? i'm just curious for my use at home. i think i have latex2e there. – aeroNotAuto Mar 17 '12 at 16:55
See tug.org/texlive and it has pdfTeX 3.1415926-2.3-1.40.12 (TeX Live 2011) – Herbert Mar 17 '12 at 17:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.