How to generate automatic numbering of table titles in word using knit in Rmarkdown?
Asked Answered
P

1

1

I'm doing a markdown report for my work. I need the outputs in word. Although with KABLE I can place titles on my tables, they are not numbered.

What should I add to kable () or in YAML to get automatic numbering of my tables?

crude example of what I do:

table(cars$speed) %>% 
  as.data.frame() %>% 
  kable(caption = "title",digits = 0, format.args = list( decimal.mark = ",",big.mark = "."),booktabs = T) %>% 
  kable_styling(latex_options = c("hold_position"))
Phan answered 18/11, 2020 at 15:38 Comment(0)
C
2

To do this you will need to use the bookdown extensions to markdown. The following is an example rmarkdown (.Rmd) file which does want you want:

---
output:
  bookdown::word_document2
---

See Table \@ref(tab:myfirsttable).  

```{r myfirsttable, echo = FALSE}
knitr::kable(head(cars, 3), caption = "First three rows of cars dataset")
```

See Table \@ref(tab:mysecondtable).

```{r mysecondtable, echo = FALSE}
knitr::kable(head(iris, 3), caption = "First three rows of iris dataset")
```

Once generated the word document looks like:

enter image description here

For more information see:
https://bookdown.org/yihui/bookdown/a-single-document.html https://bookdown.org/yihui/bookdown/tables.html

Conley answered 20/11, 2020 at 0:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.