使用knitr和latex在Beamer中编码块字体大小 [英] Code chunk font size in Beamer with knitr and latex
问题描述
我正在尝试让一些 R 代码适合我的投影仪幻灯片.似乎不可能通过代码块的 size
参数更改字体大小,就像您对其他 knitr 类型文档所做的那样.唯一的方法似乎是在每个代码块之前使用 footnotesize
.这令人沮丧,因为我有很多代码块,而且在很多情况下,我必须在 LaTeX 项目符号点之后使用
ormalsize
.
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 size
argument for the code chunk as you might do for other knitr type documents. The only way seems to be with footnotesize
before every code chunk. This gets frustrating, as I have lots of code chunks and in many cases I then have to use
ormalsize
after for my LaTeX bullet 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)
```
在我的 header.txt
(如下)中,我尝试了一些来自 http://yihui.name/knitr/demo/beamer/ 但没有运气.
In my header.txt
(below) I have experimented with a couple of bits of code from http://yihui.name/knitr/demo/beamer/ but with no luck.
ifdefinedknitrout
enewenvironment{knitrout}{egin{footnotesize}}{end{footnotesize}}
else
fi
makeatletter
letoldallttalltt
defalltt{@ifnextchar[alltt@i alltt@ii}
defalltt@i[#1]{oldalltt[#1]footnotesize}
defalltt@ii{oldallttfootnotesize}
makeatother
...但 def
真的超出了我的深度.
... but really out my depth with def
.
推荐答案
借鉴this tex.SE answer,我们可以重新定义围绕 R
代码的 Shaded
环境,使其成为脚注大小(以及用于输出的 verbatim
环境).将此添加到您的 header.txt:
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
letoldShadedShaded
letendoldShadedendShaded
enewenvironment{Shaded}{footnotesizeoldShaded}{endoldShaded}
%% change fontsize of output
letoldverbatimverbatim
letendoldverbatimendverbatim
enewenvironment{verbatim}{footnotesizeoldverbatim}{endoldverbatim}
这篇关于使用knitr和latex在Beamer中编码块字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!