[R] Sweave: Changing the background color, adding a border
Romain Francois
romain.francois at dbmail.com
Sun Apr 19 12:44:39 CEST 2009
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
More information about the R-help
mailing list