3

I'm trying to create tables with cross-references in Quarto that are rendered in MS Word
So far I get the best looking tables with flextable
However, I haven't managed to get the cross-references to work yet

Here's the qmd file contents showing an example adapted from https://ardata-fr.github.io/flextable-book/captions-and-cross-references.html

---
title: "Cross-reference example"
format: docx
editor: visual
---

```{r include=FALSE}
library(knitr)
library(flextable)
opts_chunk$set(echo = FALSE)
# example from https://ardata-fr.github.io/flextable-book/captions-and-cross-references.html
```

```{r}
ft <- qflextable(head(airquality))
```

# Captions

Now, let's add a caption with `set_caption`:

```{r ft.align="left"}
library(officer)
set_caption(ft, 
  caption = "airquality dataset", 
  style = "Table Caption", 
  autonum = run_autonum(seq_id = "tab", bkm = "tab1"))
```

Or use kintr chunk options:

```{r ft.align="center", tab.cap='airquality dataset', tab.id='tab2', label='tab2'}
ft
```

Or build label into caption:

```{r ft.align="center", tab.cap='airquality dataset {#tab:tab3}'}
ft
```

# Cross-references

* This is a reference to flextable \@ref(tab:tab1).
* This is a reference to flextable \@ref(tab:tab2).
* This is a reference to flextable \@ref(tab:tab3).

# Links

* This is a link to [flextable](#tab:tab1)
KJB
  • 121
  • 6
  • 2
    `flextable` has some issues in working with `quarto` which has some workarounds, but not quite the solution. See [github issue thread](https://github.com/davidgohel/flextable/issues/385). Also table caption and cross ref is not working with quarto. See [this github issue](https://github.com/quarto-dev/quarto-cli/issues/1556). I would suggest to try other package for now. – shafee Aug 14 '22 at 03:40
  • thanks for the references, will follow from what I've seen, quarto generated tables using `xtable` and `kable` loose their formatting when rendered in word is there another option I should be looking at? am starting to think it is too soon to pursue quarto/word – KJB Aug 15 '22 at 13:02
  • 2
    Well, I know of two R packages that support table output to Word Document, which are `flextable` and `huxtable` but unfortunately, table cross-referencing in quarto is not working with either of them. – shafee Aug 15 '22 at 15:41

1 Answers1

0

see the quarto issue update which solves most of the problem and includes a work around for the remainder

KJB
  • 121
  • 6