[R] Sweave: Changing the background color, adding a border

Duncan Murdoch murdoch at stats.uwo.ca
Sun Apr 19 12:26:11 CEST 2009


On 19/04/2009 6:03 AM, Christophe Genolini wrote:
> Hi all,
> 
> I am using Sweave to produce a document. Unfortunately, I have to print 
> several copies and I can't print them in color. So I would like to 
> change the way of printing the code. I would like to print the code in a 
> box with a black borderline and a grey background (quite classic). Is it 
> possible to do it by changing some Schunk options?

It should be, if you know how to print things like that, but I don't 
Here's some code I wrote a while ago to modify the Sweave formats in a 
much simpler way:

% This removes the extra spacing after code and output chunks in Sweave,
% but keeps the spacing around the whole block.

\fvset{listparameters={\setlength{\topsep}{0pt}}}
\renewenvironment{Schunk}{\vspace{\topsep}}{\vspace{\topsep}}
% We want to avoid having examples switch us to an italic font shape.
\DefineVerbatimEnvironment{Soutput}{Verbatim}{fontshape=n}

Presumably some combination of \renewenvironment, \fvset (which sets 
fancyvrb parameters), or \DefineVerbatimEnvironment (a fancyvrb command) 
should do what you want.

Duncan Murdoch



More information about the R-help mailing list