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 want to include only parts of an image. For this, I use the viewport option of graphicx's includegraphics. To find the coordinates, I go by trial and error, adapting the viewport argument until I have it right. This is inefficient.

\includegraphics[viewport=0 0 10 10,clip]{image}

Is there some way I can easily obtain/draw a grid to efficiently select the coordinates to pass to viewport? For example, when I want to draw on an image using tikz, I draw helplines according to this post. In this case, I don't want to draw at all; I just want to include a specified part of the image only.

share|improve this question
Have a look at tex.stackexchange.com/a/45023/963 – Yiannis Lazarides Apr 29 '13 at 18:21
I think it has been discussed here. – kiss my armpit Apr 29 '13 at 18:30
I'm not sure if I'm understood correctly, I will edit the question. – gerrit Apr 29 '13 at 18:32
up vote 7 down vote accepted
\usepackage[abs]{overpic}% option [abs] for absolute values 

  \put(50,50){\makebox[0pt]{\colorbox{blue}{\color{white}\Huge Tiger}}}

\fbox{\includegraphics[viewport=80mm 120mm 120mm 160mm,scale=0.5,clip]{tiger}}


enter image description here

The absolue values are scaled down, the reason why I had to double the coordinates for the eye.

share|improve this answer
Perhaps I did not phrase my question clearly. The coordinates in this figure do not correspond to the coordinates I need to pass to viewport to get my desired subset of the image; for example, suppose I want to include only the right eye. \includegraphics[viewport=39 60 44 64,clip]{tiger} does not give me the right eye, but a different (much smaller) area. – gerrit Apr 29 '13 at 18:38
I set the unit to mm and scaled the image to 0.5! – Herbert Apr 29 '13 at 18:43
I find it hard to reproduce it with my local example here. I might be still doing something wrong. Does it make a difference in what format the picture is? – gerrit Apr 29 '13 at 18:55
no, the picture doesn't matter. Can you put it anywhere for a download? However, try it first with my example. – Herbert Apr 29 '13 at 18:56
Looks like I was missing the abs option (I think it wasn't there in an earlier revision), but that one's pretty essential. Got it now! – gerrit Apr 29 '13 at 19:13

With PSTricks.

\documentclass[preview,border=12pt]{standalone}% remove border option to get a tight output

\def\M{10}% columns
\def\N{10}% rows
\def\scale{1}% scale
\def\filename{shaolin}% filename






\def\viewport(#1,#2)(#3,#4){\includegraphics[scale=\scale,viewport=#1 #2 #3 #4,clip]{\filename}}

%\Navigator% disable it after using

How to use:

  1. \Nagivator will show the grid from which we determine the viewport coordinates.

    enter image description here

  2. \ViewPort is used to clip everything outside viewport.

    enter image description here

  3. Remove border option in the document class to get a tight output.

share|improve this answer

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.