7

I am trying to change the font size of a code chunk (more precisely I want to use a smaller font). Take the following basic example:

---
title: "Example"
output:
  ioslides_presentation:
  toc: yes
widescreen: yes
---

## Code

```{r, eval=FALSE}
print(mtcars)
```

Anyone an idea? Is there a YAML option like code-font-size or something like that?

Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98

1 Answers1

7

You can change the default font size document wide using

<style>
pre {
  font-size: 20px;
}
</style>

which you can put right underneath your YAML header or in a seperate stylesheet (CSS file) that you can include in your YAML.

You may want to change the settings for padding and margin as well in order to prettify chunk layout.

Modify single chunks

It is possible to add a class to the code chunks you want to modify (if not all of them). Check out the answer here: stackoverflow.com/questions/37944197/

Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
  • I didn't edit the file, but put this entire bit of CSS code at the top of my Rmd file and edited it there. It overrode the settings and was able to output the code font size I wanted. Cheers! – bhive01 Jan 28 '16 at 20:33
  • Yeah that works as well of course. You could also just make a copy, edit that one and include it in the YAML header of your markdown script. – Martin Schmelzer Jan 29 '16 at 08:30
  • In addition this answer might be helpful to modify single code chunks: http://stackoverflow.com/questions/37944197/add-a-css-class-to-single-code-chunks-in-rmarkdown – Martin Schmelzer Jul 18 '16 at 18:48