Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

r - Internal links in rmarkdown don't work

I use rmarkdown to render pdf documents. Now I want to add internal links in the texts.

In the helping pages of rmarkdown, it says an internal link is defined as:

See the [Introduction](#introduction).

When I Use e.g. the next code there should be two internal links: link1 and link2. Both don't link. Is there something obvious that I am doing wrong? Many thanks in advance!

   ---
title: "Test"
author: "test test"
output:
  pdf_document:
    latex_engine: xelatex
    number_sections: yes
    toc: yes
    toc_depth: 3
  html_document:
    css: tables.css
    number_sections: yes
    theme: cerulean
    toc: yes
    toc_depth: 3
subtitle: test test test
mainfont: Calibri Light
fontsize: 12pt
header-includes:
- usepackage[dutch]{babel}
- usepackage{fancyhdr}
- pagestyle{fancy}
- fancyfoot[LE,RO]{this is a fancy foot}
- usepackage{dcolumn}
- usepackage{here}
- usepackage{longtable}
- usepackage{caption}
- captionsetup{skip=2pt,labelsep=space,justification=justified,singlelinecheck=off}
---

# start

```{r results="asis",tidy=FALSE,eval=TRUE,echo=FALSE,message=FALSE, error=FALSE, warning=FALSE, comment = NA}
cat("click here: [link1](#test 1)")
```

click here: [link2](#test 1)

pagebreak

#test 3

pagebreak

#test 2

pagebreak

#test 1
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're not setting the anchors correctly.

Try the following:

# start

```{r results="asis",tidy=FALSE,eval=TRUE}
cat("click here: [link1](#test1)")
```

click here: [link2](#test1)

pagebreak

# test 3 {#test3}

pagebreak

#test 2 {#test2}

pagebreak

#test 1 {#test1}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...