[R] Sweave/margin

Jan T. Kim jtk at cmp.uea.ac.uk
Mon Mar 21 14:51:52 CET 2005


On Fri, Mar 18, 2005 at 10:49:32PM +0100, Katharina Hoff wrote:

> I am currently using Sweave for writing my bachelor thesis - and I have a
> problem:
> 
> I am using a LaTeX style (report) with quite big margin spaces. The Sweave
> generated LaTeX code "floats" into the margin - and it looks ugly. The text
> is blocked and fine... then there comes some flattering code running over
> the margin... and blocked text again.
> 
> Considering the LaTeX output, I guess that Sweave puts the source code
> somehow in LaTeX-boxes and I suppose there is a place where I could change
> the width of the source code boxes (At a certain point, there is a break,
> closely before the text would drift out of the page. Then the code continues
> in new lines below.)
> 
> Does anyone know where I could change or insert the box width? 
> 
> Or probably I am totally wrong and someone knows another solution...
> 
> Hoping for help - and excuse if anyone asked this stupid question before, I
> did not find it in the archive,

I assume you talk about R code lines extending into the right margin of
pages. These are due to the formatting of such stuff using Verbatim
environments.

To gain control over code formatting, you can copy the pertinent lines
from Sweave.sty into your document's preamble:

    \usepackage{fancyvrb}

    % \usepackage{Sweave}

    \DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
    \DefineVerbatimEnvironment{Soutput}{Verbatim}{}
    \DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}

    \newenvironment{Schunk}{}{}

The comment "% \usepackage{Sweave}" is needed, it suppresses the insertion
of that usepackage line by Sweave.

My Sweave manual just mentions that you are to define Sinput and Soutput,
but in fact, both are wrapped by the currently (R 2.0.1) unused Schunk
environment, providing you with a convenient handle for altering the font
size, as e.g. in:

    \newenvironment{Schunk}{\tiny}{}

Alternatively, you can make use of the fontsize parameter provided by the
Verbatim package of LaTeX.

Finally, you can always try to tweak your R code to consist of, and to produce
shorter lines.

Best regards, Jan
-- 
 +- Jan T. Kim -------------------------------------------------------+
 |    *NEW*    email: jtk at cmp.uea.ac.uk                               |
 |    *NEW*    WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*




More information about the R-help mailing list