I would like to crop an image that is not inserted (which has been searched a lot), but an image that is generated in R code.



<<label=plotName, include=FALSE>>=

\setkeys{Gin}{width=4in, height=4in}
\caption{Some caption.}

I tried to insert a statement as follows:

\includegraphics[clip=true,trim=0cm 1cm 0cm 1cm]

I did this in several locations, but for instance, immediately in the line after \begin{center}, I get an error ("Undefined control sequence").

Any suggestions would be greatly appreciated!

  • You will have better success with trimming the figure inside the Sweave block using the R plot options commands. Commented Feb 25, 2015 at 1:19

1 Answer 1


The adjustbox package provides the adjustbox environment which you should be able to use for this purpose. Your setup should resemble:

% ... preamble content

% ... main document content

  \begin{adjustbox}{width=4in,height=4in,clip,trim=0cm 1cm 0cm 1cm}
  % ...sweave content

% ... other main document content


Note the use of \centering rather than the center environment.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .