I am using Knit PDF to compile a beamer presentation in RStudio.
我正在使用Knit PDF在RStudio中编译beamer演示文稿。
---
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?
如何更改字体大小(仅适用于此一个块,其他块保持相同的字体大小),以便此命令的输出适合一张幻灯片?
2 个解决方案
#1
8
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.
一种解决方案是使用针织钩。钩子是在块代码执行之前或之后运行的代码。您可以使用它在文件中插入LaTeX fontsize命令。
```{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
```
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-Code。虽然很麻烦,但你可以使用两个连续的块(第一个:echo,结果没有;第二个:没有回声,结果是)来逃避这个。
```{r results="'hide'}
1:10
```
```{r echo=FALSE, mysize=TRUE, size='\\large'}
1:10
```
PS. Maybe there is a better way by modifying output hooks instead of chunk hooks.
PS。也许通过修改输出挂钩而不是块挂钩有更好的方法。
#2
0
Here's how i do it ...
这是我怎么做的......
add the following to your slideStyle.sty
file
将以下内容添加到slideStyle.sty文件中
% set font size to 7 with line breaks at 8
\newcommand\FontSmall{\fontsize{7}{8}\selectfont}
call the file at the top of your markdown:
调用降价顶部的文件:
output:
beamer_presentation:
includes:
in_header: "P:/R/Slides/slideStyles.sty"
and then in your .Rmd
file add the below
然后在你的.Rmd文件中添加以下内容
## Tiny font slide
\FontSmall
here is some tiny font ...
#1
8
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.
一种解决方案是使用针织钩。钩子是在块代码执行之前或之后运行的代码。您可以使用它在文件中插入LaTeX fontsize命令。
```{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
```
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-Code。虽然很麻烦,但你可以使用两个连续的块(第一个:echo,结果没有;第二个:没有回声,结果是)来逃避这个。
```{r results="'hide'}
1:10
```
```{r echo=FALSE, mysize=TRUE, size='\\large'}
1:10
```
PS. Maybe there is a better way by modifying output hooks instead of chunk hooks.
PS。也许通过修改输出挂钩而不是块挂钩有更好的方法。
#2
0
Here's how i do it ...
这是我怎么做的......
add the following to your slideStyle.sty
file
将以下内容添加到slideStyle.sty文件中
% set font size to 7 with line breaks at 8
\newcommand\FontSmall{\fontsize{7}{8}\selectfont}
call the file at the top of your markdown:
调用降价顶部的文件:
output:
beamer_presentation:
includes:
in_header: "P:/R/Slides/slideStyles.sty"
and then in your .Rmd
file add the below
然后在你的.Rmd文件中添加以下内容
## Tiny font slide
\FontSmall
here is some tiny font ...