Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set caption font size for figures in YAML header of Rmarkdown

I am using Rstudios markdown to write a report which I would like to compile to pdf using latex as well as to html...

Is it somehow possible to adjust the size of caption fonts for images included in an ![caption](figure.jpg) environment? At the moment captions in html look like the rest of the text.

like image 715
mhwh Avatar asked Dec 04 '22 00:12

mhwh


1 Answers

This answer has obviously already been accepted but just for completeness I am adding the PDF aspect of the question.

If you wish to alter the caption font size for your PDF documents I would recommend to use the caption package via one of the following two approaches:

header-includes - option:

---
title: "Title"
author: "Jorge Luis Borges"
header-includes:
  - \usepackage[font={small}]{caption}
output:
  pdf_document
---

The focus here is on font={<font options>}.

in_header - option:

---
title: "Title"
author: "Jorge Luis Borges"
output:
  pdf_document:
    includes:
      in_header: style.tex
---

Where style.tex is included in the same directory that contains the .Rmd file. The style.tex file needs to contain \usepackage[font={small}]{caption}.

As before, the focus here is on font={<font options>}.


With the caption package you have loads of customisation options, just to name a few, see below:

  • scriptsize = very small size
  • footnotesize = size typically used for footnotes
  • small = small size
  • large = large size
  • it = italics
  • bf = bold face

For full reference please visit the official documentation.

Also, some cross-references here to articles on the TexSE site:

Change the font of figure captions

How to include Latex package in RMarkdown

like image 67
Johnny Avatar answered Dec 06 '22 14:12

Johnny