Beamer presentation RStudio change font size for chunk

偶尔善良 提交于 2019-12-21 04:08:34

问题


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?


回答1:


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
```

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. Maybe there is a better way by modifying output hooks instead of chunk hooks.




回答2:


Here's how i do it ...

add the following to your slideStyle.sty file

% 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

## Tiny font slide

\FontSmall

here is some tiny font ...


来源:https://stackoverflow.com/questions/26372138/beamer-presentation-rstudio-change-font-size-for-chunk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!