Beamer演示文稿RStudio更改块的字体大小 [英] Beamer presentation RStudio change font size for chunk
问题描述
我正在使用Knit PDF在RStudio中编译投影仪演示.
I am using Knit PDF to compile a beamer presentation in RStudio.
---
title: "A.P. Statistics"
author: "Notes for Chapter 3.Rmd"
date: "Monday, October 13, 2014"
output: beamer_presentation
---
## Computer Output
```{r}
summary(lm(cars$dist~cars$speed))
```
如何更改字体大小(仅针对这一块,其他块保持相同的字体大小),以使此命令的输出适合一张幻灯片?
How can I change the font size (just for this one chunk, leaving other chunks the same font size) so that the output of this command fits on one slide?
推荐答案
一种解决方案是使用knitr
钩子一个>.挂钩是将在执行块代码之前或之后运行的代码.您可以使用它在文件中插入LaTeX fontsize命令.
One solution is using knitr
hooks. A hook is code that will run before or after the chunk code is executed. You could use it to insert a LaTeX fontsize command in the file.
```{r echo=FALSE}
knitr::knit_hooks$set(mysize = function(before, options, envir) {
if (before)
return(options$size)
})
```
知道您可以通过以下方式更改大小
Know you can change the size by
```{r mysize=TRUE, size='\\large'}
1:10
```
一个缺点是这种钩子会影响幻灯片上的所有字体,即回显的R代码.尽管很麻烦,但您可以使用两个连续的块(第一个:echo,结果为否;第二个:没有echo,结果为)来规避这一点.
One Drawback is that this type of hook will affect all the fonts on a slide, i.e. also the echoed R-Code. Though cumbersome, you could use two consecutive chunks (1st: echo, results no; 2nd: no echo, results yes) to evade this.
```{r results="'hide'}
1:10
```
```{r echo=FALSE, mysize=TRUE, size='\\large'}
1:10
```
PS.通过修改输出挂钩而不是大块挂钩,也许是一种更好的方法.
PS. Maybe there is a better way by modifying output hooks instead of chunk hooks.
这篇关于Beamer演示文稿RStudio更改块的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!