Hello,
I am writing a report in R Markdown. This report will contain a table with three columns, the third of which contains cross-references to sections elsewhere in the document. I have to output the document to .docx. Is there a way to have R Markdown/bookdown cross-references being output correctly in a Word table (preferably using the {flextable} package).
A reprex (stolen - I would call it recycled - from this post) is included below.
---
title: "Can we do this using bookdown::word_document2?"
output: bookdown::pdf_document2
---
# Section {#ref1}
## Sub section {#ref1-1}
# A different section {#ref2}
```{r echo = FALSE}
suppressMessages(library(tidyverse))
suppressMessages(library(flextable))
cross_references <- tibble(
Section_Name = c("Section", "Sub section", "A different section"),
Section = c("Section \\@ref(ref1)", "Section \\@ref(ref1-1)", "Section \\@ref(ref2)")
)
ft_cross_reference <- flextable(cross_references)
ft_cross_reference
The cross-references display correctly when the output is PDF (i.e. when output: bookdown::pdf_document2 but only "Section \@ref(ref1)" when the output is Word.
Is it even possible to have cross-references work correctly in a table in Word?
All help is most welcome!
Rikard