pdflatexr-markdownfont-sizetableofcontents

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


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!


Solution

  • 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.

    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