14
votes

I'm using rmarkdown to produce a word (.docx) report. I would like to change the header of the toc. This seems possible as pandoc_args can be passed as options in the yaml header in the case of a doc file (1). But I'm not doing it right. Could anyone provide a working example ?

(1) pandoc.args is included in the rmarkdown possible options and in the pandoc manual, there is a toc-title option

---
title: "yaml header"
author: "cedric"
output:  
  word_document:
   toc: true
pandoc_args: toc-title="Table des matières"
---
# One section
# Another

This produces :

document without change in toc_title

1

1 Answers

25
votes

The title of the table of contents is document metadata, so you can set it with YAML metadata block.

---
title: "yaml header"
author: "cedric"
output:  
  word_document:
    toc: true
toc-title: "Table des matières"
---

Or passed it in with the -M command-line flag.

---
title: "yaml header"
author: "cedric"
output:  
  word_document:
    toc: true
    pandoc_args: [
      "-M", "toc-title=Table des matières"
    ]
---