Choose font size for table of contents only in a rmarkdown-rendered pdf

86 Views Asked by At

How can I change the font size of the toc only when rendering an rmarkdown document as pdf?

I am only aware of the fontsize: parameter in the YAML, but it changes the font size of the whole pdf document. Is there any other parameter specific for the toc? Perhaps via .css file?

Thanks!

1

There are 1 best solutions below

0
shafee On BEST ANSWER

Using CSS will not affect the pdf output, CSS only affects those output formats that generate an HTML file as an output. You need to search for LaTeX commands or packages to make changes in pdf output.

And the package tocloft package provides means of controlling the typographic design of the Table of Contents. From the tocloft documentation - section 2.3 Typesetting entries,

tocloft provides \cftXfont where X denotes.

  • part for \part titles
  • chap for \chapter titles
  • sec for \section titles
  • subsec for \subsection titles
  • subsubsec for \subsubsection titles

And you can use \cftXfont to change the font size of table of contents texts.

---
title: "Changing font size of TOC"
output: 
  pdf_document:
    number_sections: true
    toc: true
header-includes:
  - \usepackage{tocloft}
  - \renewcommand\cftsecfont{\huge}
---


# R Markdown

This is an R Markdown document. 


# Including Plots

You can also embed plots.

Table of Contents with huge font size