Search code examples
rlatexr-markdownmarkdownbookdown

Manipulating the font size of headings, footnote and table description in bookdown (for pdf_book)


I want to change the default font size for specifically heading, footnote and table and figure descriptions for all the chapters in advance (e.g. by specifying the desired size in the index.Rmd yaml). For example, when I do fontsize=10pt in the yaml it nicely changes main body text sizes to 10pt. Is there a way that I can similarly manipulate font size of heading, footnote and table and figure descriptions in my book?

Here is an example how the yaml of the index.Rmd file looks like.

--- 
title: "Looking for some help to change font size of headings in my book."
author: "Bird"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
mainfont: Times New Roman
fontsize: 10pt
geometry: "left=2.5cm, right=2cm, top=2.5cm, bottom=2.5cm"
linestretch: 1.5
toc-depth: 1
secnumdepth: 1
lof: True
lot: True
---

Solution

  • Here is a solution to change the default font size locally.

    ---
    title: "Untitled"
    author: "bttomio"
    date: "4/26/2021"
    output: pdf_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ## \scriptsize Use one slash for headings (\\scriptsize)
    
    For the footnote, it works similarly. Check here^[\tiny Using \\tiny.]
    
    ## \huge Table description with {kableExtra} (\\huge)
    
    For example:
    
    ```{r pressure, echo=FALSE}
    library(kableExtra)
    kbl(mtcars[1:2, 1:4], booktabs = T, linesep = "", caption = "\\huge Test with huge", escape = F) %>%
      kable_styling(latex_options = "hold_position")
    ```
    

    More styles, following LaTeX code: https://i2.wp.com/texblog.org/Wordpress/wp-content/uploads/2012/08/font-size21.png (Source).

    -output

    enter image description here