I'm using Sweave to produce a large, multi part academic thesis. I had neglected to specify \usepackage{Sweave} in my preamble, but everything was working fine until I added some verbatim output from R. The latex compiler threw some errors that keyed me in to my omission of the \usepackage{Sweave} directive.

When I added \usepackage{Sweave} to my preamble, the verbatim output worked fine, but many images in my document suddenly got scaled strangely. The seem to keep their height, but their width was expanded.

Generally I scale my images by specifying height, such as: \includegraphics[height=1.5in]{graphicName}. If I instead specify \includegraphics[height=1.5in, keepaspectratio=true]{graphicName} I get the expected behavior. I've never needed this additional flag before.

Why is Sweave changing the default behavior of \includegraphics{}?

Apologies for the lack of a minimal reproducible example here, but my document structure is pretty complex at this point.

  • Are you using the graphicx package? Sweave.sty loads that package svn.r-project.org/R/trunk/share/texmf/tex/latex/Sweave.sty . If so, you could try ensuring graphicx loads before Sweave. – Peter May 14 '13 at 19:25
  • I am using graphicx, and its include statement is above Sweave's. – mac May 14 '13 at 19:28
  • Perhaps you should try knitr instead. – Yihui Xie May 21 '13 at 18:55

The sweave style sets the default figure width.

In svn.r-project.org/R/trunk/share/texmf/tex/latex/Sweave.sty the relevant line is:


This can be turned off using the nogin package option:


| improve this answer | |
  • Thanks, but what's Gin? Should I know this name from elsewhere? Seems a bit cryptic. – mac May 14 '13 at 19:39
  • 1
    Gin is a set of keys in the graphicx package that can be set to control figure sizes without changing each \includegraphics command: engineering.purdue.edu/~mark/puthesis/missing-files/… – Peter May 14 '13 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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