Beamer block code font size with ketter and latex

I am trying to get some R code to fit on the slider slides. It is not possible to change the font size using the size argument for a piece of code, as you would for other documents like knitr. The only way, apparently, is to \footnotesize before each piece of code. This is frustrating since I have many pieces of code, and in some cases I have to use \normalsize after my LaTeX ballet points.

 --- title: "Untitled" output: beamer_presentation: includes: in_header: header.txt --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE, size = "footnotesize") ``` ## R Markdown ```{r} summary(cars) ``` \footnotesize ```{r} summary(cars) ``` 

enter image description here

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

 \ifdefined\knitrout \renewenvironment{knitrout}{\begin{footnotesize}}{\end{footnotesize}} \else \fi \makeatletter \let\oldalltt\alltt \def\alltt{\@ifnextchar[\alltt@i \alltt@ii} \def\alltt@i[#1]{\oldalltt[#1]\footnotesize} \def\alltt@ii{\oldalltt\footnotesize} \makeatother 

... but really, my depth is with \def .

+8
r knitr latex beamer
source share
1 answer

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

 %% change fontsize of R code \let\oldShaded\Shaded \let\endoldShaded\endShaded \renewenvironment{Shaded}{\footnotesize\oldShaded}{\endoldShaded} %% change fontsize of output \let\oldverbatim\verbatim \let\endoldverbatim\endverbatim \renewenvironment{verbatim}{\footnotesize\oldverbatim}{\endoldverbatim} 
+3
source share

All Articles