Tag Archives: LaTeX

Reproducible presentations

Yesterday I wrote about my experience trying out Beamer for writing presentations in LaTeX. Some of the images that I’m wanting to include in my presentations are plots produced in R, so one simplification would be to combine Beamer with Sweave. That way I could include code for producing the images directly in my presentation file rather than referencing external image files. Any change to the R code would be automatically reflected in my presentation.

One problem I had when turning a LaTeX Beamer file into a Sweave file was image sizes. When an Sweave file has documentclass{article}, plots are modestly sized and centered. But when I tried including a plot with an Sweave file with documentclass{Beamer}, the image was so large that it covered up other material on the slide. The solution was to include the following line immediately after the begin{document} command:

setkeys{Gin}{width=0.6textwidth}

(See section 4.1.2, page 14 of the Sweave manual.) This command made the image the size I wanted, but the image was no longer centered. To center the image, I added begin{center} before and end{center} after the Sweave figure command. This worked. A sketch of the code is included below.

documentclass{Beamer}
begin{document}
setkeys{Gin}{width=0.6textwidth}

begin{frame}
frametitle{...}

Slide verbiage ...

begin{center}
<<&fig=TRUE, echo=FALSE>>=
# R code ...
@
end{center}