Using Sweave with Beamer: A note on fonts

November 2, 2011
By

(This article was first published on The Praise of Insects, and kindly contributed to R-bloggers)

Recently, I've been preparing a poster using the LaTeX packages Beamer and beamerposter. The poster discusses a bunch of R stuff that I've been doing lately, so I successfully used Sweave to incorporate R code into the poster. However, I had some trouble with package names that I wanted to typeset as small caps. The package names looked the same as the rest of the text. A bit of sleuthing around revealed Sweave as the culprit. In the Sweave.sty package, on line 20, it calls the deprecated LaTeX package "ae", which for some reason doesn't recognise small caps. Changing the package to "lmodern" made small caps turn up correctly within the text.

Unfortunately, my problems had not yet been solved completely. I had mentioned the package names in the titles which were set in bold. I thus had created a fairly commonly encountered bugbear with LaTeX—the non-compatibility of bold and small caps in computer modern font. While there are workarounds for this (see this Stack Exchange and TeX FAQ for more details), unfortunately these solutions did not work with Beamer.

So, I set about finding a font that both looked alright, and would accomodate bold and small caps. I found that using helvetica would be fine, but had to be loaded after Sweave to work. As my Sweave block kept placing the \usepackage{Sweave} immedediately before \begin{document}, I resorted to calling helvetica in the Sweave file itself.

The relevant lines in of the Sweave.sty (lines 18-21) file. Before:
\ifthenelse{\boolean{Sweave@ae}}{%
\RequirePackage[T1]{fontenc}
\RequirePackage{ae}
}{}%
After:
\ifthenelse{\boolean{Sweave@ae}}{%
\RequirePackage[T1]{fontenc}
\RequirePackage[scaled]{helvet}
}{}%

To leave a comment for the author, please follow the link and comment on his blog: The Praise of Insects.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.