3
votes

I'm trying to create a R markdown document and use custom colours for the links in the document. This works for external links, but not for the ones in the table of contents. It was my understanding that the linkcolor attribute should take care of that, but it doesn't work for me.

Here's my workflow:

Document:

---
title: "test"
output:
    pdf_document:
      toc: true
linkcolor: red
urlcolor: red
citecolor: red
---

# Foo

## Fooo

foo foo foo [link](https://duckduckgo.com)

# Bar

## Bar Bar

bar bar bar

To render, I'm using rmarkdown::render in R. In Unix systems, you can just run this line (provided you saved the given example as doc.Rmd):

echo "rmarkdown::render('doc.Rmd', output_file='doc.pdf')" | R
2

2 Answers

2
votes

Figured it out.

Using the hyperref package allows all sorts of link customisation.

Example header:

---
title: "test"
output:
    pdf_document:
      toc: true
header-includes:
    - \usepackage {hyperref}
    - \hypersetup {colorlinks = true, linkcolor = red, urlcolor = red}
---
1
votes

Here is a simpler solution using the toccolor option:

---
output: pdf_document
toc: true
toccolor: 'red'
---

# section 1
# section 2

Compiled pdf