1

I am creating a presentation in rmarkdown for the first time. I am using the isoslides output option. I would like to format code chunk output to better fit on the slides, but I can't seem to find a reasonably easy way to do this. Is there a way to just change output size in the chunk options? The code below will print the data frames but they need to be smaller to fit on the slide.

---
title: "My Presentation"
author: "My Name"
date: "September 10, 2018"
output: ioslides_presentation
---

## Data Processing 
  * One-hot encoding example.
```{r, message = FALSE}
library(dummies)
head(iris)
iris_1H <- dummy.data.frame(iris)
head(iris_1H)
```
user29609
  • 1,991
  • 18
  • 22

1 Answers1

0

You can change the font size of code chunks by changing the font size and line height of the pre tags, and include this as a CSS <style> block after the YAML header.

---
title: "My Presentation"
author: "My Name"
date: "September 10, 2018"
output: ioslides_presentation
---

<style>
pre {
    line-height: 1.2em;
    font-size: 10px;
}
</style>

## Data Processing 
  * One-hot encoding example.

```{r, message = FALSE}
library(dummies)
head(iris)
iris_1H <- dummy.data.frame(iris)
head(iris_1H)
```

This produces

enter image description here

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
  • Thanks! Is there a way to do it chunk by chunk? – user29609 Sep 11 '18 at 23:32
  • @user29609 In that case, the question is a duplicate of [Add a CSS class to single code chunks in RMarkdown](https://stackoverflow.com/questions/37944197/add-a-css-class-to-single-code-chunks-in-rmarkdown) – Maurits Evers Sep 11 '18 at 23:38
  • I don't have the class or class.source options available in my code chunks. I put the css snippet in a file called class.css and added class = "class" to the chunk but it does not have an effect. If I put the css code at the top of my presentation under the yaml it will work for all chunks. I have the recent version of all packages. – user29609 Sep 12 '18 at 00:00
  • @user29609 Take another (closer) look at the linked post. You need to define a class in your CSS file (e.g. `.myClass`), and then add that class to a particular code chunk with `class.source='myClass'`. I just checked and it works just fine. – Maurits Evers Sep 12 '18 at 00:43
  • Where do you call the name of your separate css file? I think that is the part that is tripping me up. I am not familiar with CSS. – user29609 Sep 12 '18 at 17:36