Search code examples
rknitrtableofcontents

How to change table of content header in knitr?


I am using the following options to produce a pdf document with knitr:

---
title: "Test"
author: "Paulo Miramor"
date: "13-07-2015"
output: pdf_document
toc: yes
---

I would like to change the header of the table of contents (which is "Contents"), since I am producing a document in Portuguese. Is there any way to customize it?


Solution

  • Thanks to @Molx and @Chris in the comments I could find a solution.

    Solution 1

    Add \renewcommand{\contentsname}{Índice} to the document so that the .Rmd header is:

    ---
    title: "Test"
    author: "Paulo Miramor"
    date: "13-07-2015"
    output: pdf_document
    header-includes:
       - \renewcommand{\contentsname}{Whatever}
    toc: yes
    ---
    

    With this solution the header is Whatever you put inside \contentsname argument.

    Solution 2

    Add lang: portuguese to the document so that the .Rmd header is:

    ---
    title: "Test"
    author: "Paulo Miramor"
    date: "13-07-2015"
    output: pdf_document
    lang: portuguese
    toc: yes
    ---
    

    Using this solution the header was a translation of "Contents" to Portuguese. This should work if your TeX installation supports the language.