Using Sweave with Beamer: A note on fonts

[This article was first published on The Praise of Insects, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 their blog: The Praise of Insects.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)