gjabel gjabel - 1 year ago 465
LaTeX Question

Code chunk font size in Beamer with knitr and latex

I am trying get some R code to fit on my beamer slides. It does not seem possible to change the font size via the

argument for the code chunk as you might do for other knitr type documents. The only way seems to be with
before every code chunk. This is getting frustrating, as I have lots of code chunks and in some cases I have to use
after for my LaTeX bullet points.

title: "Untitled"
in_header: header.txt

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, size = "footnotesize")

## R Markdown



enter image description here

In my
(below) I have experimented with a couple of bits of code from http://yihui.name/knitr/demo/beamer/ but with no luck.


\def\alltt{\@ifnextchar[\alltt@i \alltt@ii}

but really out my depth here.

Answer Source

Drawing on this tex.SE answer, we could redefine the Shaded environment that surrounds R code to make it footnotesize (and the verbatim environment for output). Add this to your header.txt:

%% change fontsize of R code

%% change fontsize of output
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download