davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
554 stars 79 forks source link

Cross referencing does not work when changing seq_id (MS Word output) #541

Closed eeenilsson closed 1 year ago

eeenilsson commented 1 year ago

Using rmarkdown::render to knit the following .rmd file below. The cross reference does not work in MS Word, displaying a ? at the reference and a table caption looking like this "(#stab:airquality6)airquality dataset". It works as expected when seq_id is set to "tab".

Test a table with different seq_id:

This is a reference to Table \@ref(tab:airquality6).

This is a reference to Table \@ref(stab:airquality6).

```{r} 
library(officer)
ft <- flextable(head(airquality))
ft <- set_caption(ft, "airquality dataset", 
  autonum = run_autonum(seq_id = "stab", bkm = "airquality6"))
ft

sessionInfo() R version 4.2.3 (2023-03-15 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale: [1] LC_COLLATE=Swedish_Sweden.utf8 LC_CTYPE=Swedish_Sweden.utf8
[3] LC_MONETARY=Swedish_Sweden.utf8 LC_NUMERIC=C
[5] LC_TIME=Swedish_Sweden.utf8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] stringr_1.5.0 officedown_0.3.0 officer_0.6.2
[4] flextable_0.9.1 rmarkdown_2.21 knitr_1.42
[7] miceadds_3.16-18 quantreg_5.95 SparseM_1.81
[10] ggcorrplot_0.1.4 ggplot2_3.4.2 tidyr_1.3.0
[13] mice_3.15.0 dplyr_1.1.1 layout_0.1
[16] data.table_1.14.8

eeenilsson commented 1 year ago

Ok, i was using bookdown::word_document2: in the yaml header. Changing it to officedown::rdocx_document: made it work like expected.

github-actions[bot] commented 10 months ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.