Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the font size of figure captions in RMarkdown pdf output

I would like to make the font size of all captions (figures and tables) in my R Markdown document smaller. I'm using bookdown. The final output is pdf and I'm working in R Studio. To load the picture, I use the include_graphics function from knitr, because I've been told it's the best way (see here).

I only found the exact same question, but for html output here

An example .rmd:

---
output: pdf_document
---

Normal text has the same size as the captions.

```{r, echo = FALSE, out.width = '50%', fig.cap = "The caption has the same size as normal text."}
knitr::include_graphics('logo.png')
```

As you can see, the caption font size and the regular text font size are exactly the same, which doesn't look that nice. How can I solve this problem?

like image 444
symbolrush Avatar asked May 23 '19 09:05

symbolrush


People also ask

How do I increase font size in Rmarkdown?

To change the font size, you don't need to know a lot of html for this. Open the html output with notepad ++. Control F search for "font-size". You should see a section with font sizes for the headers (h1, h2, h3,...).

How do I change the font size in R notebook?

Go to the menu in RStudio and click on Tools and then Global Options. Select the Appearance tab on the left. Again buried in the middle of things is the font size. Change this to 14 or 16 to start with and see what it looks like.


1 Answers

If it's acceptable using LaTeX packages, you can use caption

---
output: pdf_document
header-includes:
   - \usepackage{caption}
   - \captionsetup[figure]{font=scriptsize}
---

Normal text has the same size as the captions.

```{r, echo = FALSE, out.width = '50%', fig.cap = "The caption has the same size as normal text."}
knitr::include_graphics('logo.png')

```

Replace scriptsize to change size. You can find a list of default LaTeX font sizes here:

https://en.wikibooks.org/wiki/LaTeX/Fonts#Built-in_sizes

The caption package on CTAN:

https://ctan.org/pkg/caption

like image 73
henrik_ibsen Avatar answered Sep 27 '22 18:09

henrik_ibsen