Christophe Genolini
2009-Apr-19 10:03 UTC
[R] Sweave: Changing the background color, adding a border
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? Christophe
Duncan Murdoch
2009-Apr-19 10:26 UTC
[R] Sweave: Changing the background color, adding a border
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
Romain Francois
2009-Apr-19 10:44 UTC
[R] Sweave: Changing the background color, adding a border
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? > > Christophe >Hi Christophe, This is not a trivial task, \Sinput and \Soutput environments are basically verbatim environments. You might want to have a look at the highlight package (not on CRAN yet) http://r-forge.r-project.org/R/?group_id=384 which ships a sweave driver that does some syntax highlighting of the code and does not rely on semi verbatim environments: require( grid ) require( highlight, lib = "~/.R/library" ) v <- vignette( "grid", package = "grid" ) file.copy( v$file, "grid.Snw" ) Sweave( "grid.Snw", driver = HighlightWeaveLatex( ) ) See the result here: addictedtor.free.fr/misc/grid.pdf The driver writes Hinput and Houtput environments instead of Sinput and Soutput, and they are defined as this in the preamble: \newenvironment{Hinput}% {}% {}% \newenvironment{Houtput}% {}% {}% So you might imagine to redefine them using some combination of fcolorbox and minipage. What happens with the box if the code spans more than one page ? Romain -- Romain Francois Independent R Consultant +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr