Home > Back-end >  Links between child documents in RMarkdown
Links between child documents in RMarkdown

Time:12-23

I am writing my PhD thesis in R Markdown and I would like to add links to one child document (Introduction) allowing the reader to jump to another child document (one of the papers).

This is my main document:

---
output: 
  pdf_document:
        latex_engine: pdflatex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F)
```
```{r chapter1, child = 'child1.Rmd'}
```
\newpage
```{r chapter2, child = 'child2.Rmd'}
```

This is how I tried to link my child1 and child2:

This is my second child document. Here I want a link to [`Child document 1`](./child2.Rmd#header1).

But when I click on the "Child document 1", it jumps to the original rmd file.

TLDR: is it possible to add clickable links between different child documents??

R version 4.2.2, Ubuntu 20, rmarkdown 2.18

CodePudding user response:

Hi it works the same way as internal links.

Parent document:

---
output: 
  pdf_document:
        latex_engine: pdflatex
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F)
```

# Parent Header


implicit internal Link to header [Parent Header]

## Child links:

This implicit links to child 1 [C1 Second header]

Here I give a explicit link to [Go to second child](#child2_header1)

\newpage

# Child 1

```{r chapter1, child = 'child1.Rmd'}
```
\newpage

# Child 2

```{r chapter2, child = 'child2.Rmd'}
```

Child 1:

---
title: "child1"
author: "Valentin Haberl"
date: "`r Sys.Date()`"
output: pdf_document
---


## I am a child document {#child1_header1}

## C1 Second header

Some more Info

Child 2.

---
title: "child2"
author: "Valentin Haberl"
date: "`r Sys.Date()`"
output: pdf_document
---


## I am a second child {#child2_header1}

Text for second child

  • Related