5

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?

Paulo MiraMor
  • 1,582
  • 12
  • 30
  • You should start with adding `lang: portuguese` to the header. If it works, you're lucky that your TeX installation supports the language. If it fails, then you should try to add this by yourself. I can't give a definitive answer because that's what I'm trying to do right now. In case you're using a debian-based linux, `sudo apt-get install texlive-lang-portuguese` might work. – Molx Jul 14 '15 at 02:56
  • See here: http://tex.stackexchange.com/a/28518/28366 – Chris Watson Jul 14 '15 at 03:12
  • @Molx and Chris, I posted an answer that is a summary of both comments, both worked for me. I hope you don't mind. If you see any problem, please post an answer and I'll accept as the correct answer and delete mine without any problems. Thanks! – Paulo MiraMor Jul 14 '15 at 03:35

1 Answers1

9

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.

Paulo MiraMor
  • 1,582
  • 12
  • 30
  • You were luckier than me then! Which TeX installation do you have? Solution1 does work, but 2 is more robust. – Molx Jul 14 '15 at 03:52
  • @Molx I'm using pdfTeX (`pdflatex`) - Linux Mint 17. I don't know if it makes any difference, but I have the `babel` package installed, although I am not calling it directly in the `.Rmd` file. – Paulo MiraMor Jul 14 '15 at 03:58
  • I think it does, since the error I get is related to `babel`. But these things work much better on Linux, I was trying on Windows but will give a shot on Ubuntu later. – Molx Jul 14 '15 at 12:13
  • Actually I just tried on a different PC with TeXWorks (Win 8.1) and it worked nicely, better than the one with other TeX installations. – Molx Jul 14 '15 at 12:17