Take the 2-minute tour ×
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.

Possible Duplicate:
Clipping support in XeTeX

Why does the crop feature not work in this example? Secondary question: Is there a good and thorough example somewhere floating around the internet explaining how to work with the bounding box and viewport etc.?

As you can see when you look at it with draft enabled and then remove the , draft code, the image is actually not being cropped. Just moved upwards by the trim feature.

What I'm trying to achieve is to crop off the very first line of characters.

MWE to be run in XeLaTeX:

\documentclass[pagesize=pdftex, 9pt]{scrbook}

\usepackage{graphicx}
\usepackage{wrapfig}

% the ratio of the embedded PDF to the text on the page
\newlength\ratiowidth
\setlength\ratiowidth{.61\textwidth}

\begin{document}
\begin{wrapfigure}{r}{\ratiowidth}
  \begin{center}
\includegraphics[width=\ratiowidth, page=1, trim=0 0 0 100, clip=true, draft]{GenesisTest.png}
\end{center}
\end{wrapfigure}

\end{document}

enter image description here

share|improve this question

marked as duplicate by Martin Scharrer Mar 23 '12 at 12:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4  
XeTeX does not have native clipping support. Martin Scharrer and I have recently done some work on fixing this at the driver level, but I am not sure if this has made it into the graphics driver at the moment. –  Joseph Wright Mar 23 '12 at 11:19
    
@JosephWright: Ok, thanks. Any particular alternative suggestions to use at this point? I unfortunately need to use XelaTeX due to other requirements. –  McGafter Mar 23 '12 at 11:25
3  
You can use my adjustbox package as an alternative. It includes a XeTeX clipping driver by itself. That's basically the same code @Joseph mentioned above. –  Martin Scharrer Mar 23 '12 at 11:28
    
I closed this now as duplicate of the earlier basically identical question because of house keeping reasons. I didn't remembered my earlier answer to that question before answering here. –  Martin Scharrer Mar 23 '12 at 12:04

1 Answer 1

up vote 7 down vote accepted

There is currently no clipping support in XeTeX. A usuable driver was suggested by Joseph Wright and me a little while ago, but it will take a good while until it is in stable release. See Clipping support in XeTeX (which I just found after my initial answer, it is actually a general duplicate).

However, you can use my adjustbox package which is inspired by graphicx but allows to apply the modification keys like clipping to arbitrary content. The current version has now also special macros to apply them directly to images. This is particular useful because then the adjustbox clipping driver for XeTeX is used, which is part of the package.

You can simply load the adjustbox package instead or in addition to graphicx and then replace \includegraphics with \adjincludegraphics (which is short for \adjustbox{<key=value options>}{\includegraphics{<filename>}). There is also a \adjustimage macro which takes the key=value options as a mandatory argument instead of an optional one.

\documentclass[pagesize=pdftex, 9pt]{scrbook}

\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{wrapfig}

% the ratio of the embedded PDF to the text on the page
\newlength\ratiowidth
\setlength\ratiowidth{.61\textwidth}

\begin{document}
\begin{wrapfigure}{r}{\ratiowidth}
  \begin{center}
\adjincludegraphics[width=\ratiowidth, page=1, trim=0 0 0 100, clip=true]{GenesisTest.png}
\end{center}
\end{wrapfigure}

\end{document}

Note that trim (with or without clip) is always applied to the original image, then the result is scaled to the given width! If you want to change the order, i.e. first resize than clip, you need to use adjustboxes Clip=0 0 0 100 key instead. This one can actually be used multiple times. See the package manual for all details.


About the bounding box and viewport: You don't need to use the bounding box keys any longer if you use EPS, PNG or JPG images. They were only needed in older times when the bounding box couldn't be read from the files directly. The viewport key is similar to trim but states the lower left and upper right corner relative to the reference point, which is the lower left corner. Instead, trim states the amount taken away from the left, bottom, right and top edges.

I made some diagrams for the new version of my adjustbox bundle (I'm planning to put the trim and clip box macros into a sub-package). See the unfinished trimclip package manual starting from page 7.

share|improve this answer

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