如何在 Rmarkdown 中使用 knit 在 word 中生成 table 标题的自动编号?
How to generate automatic numbering of table titles in word using knit in Rmarkdown?
我正在为我的工作做一个降价报告。我需要 word 的输出。尽管使用 KABLE 我可以在我的表格上放置标题,但它们没有编号。
我应该在 kable () 或 YAML 中添加什么来让我的表自动编号?
我所做的粗略示例:
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"))
为此,您需要使用 bookdown 扩展来降价。以下是您想要的 rmarkdown (.Rmd) 文件示例:
---
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")
```
生成后的 word 文档如下所示:
有关详细信息,请参阅:
https://bookdown.org/yihui/bookdown/a-single-document.html
https://bookdown.org/yihui/bookdown/tables.html
我正在为我的工作做一个降价报告。我需要 word 的输出。尽管使用 KABLE 我可以在我的表格上放置标题,但它们没有编号。
我应该在 kable () 或 YAML 中添加什么来让我的表自动编号?
我所做的粗略示例:
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"))
为此,您需要使用 bookdown 扩展来降价。以下是您想要的 rmarkdown (.Rmd) 文件示例:
---
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")
```
生成后的 word 文档如下所示:
有关详细信息,请参阅:
https://bookdown.org/yihui/bookdown/a-single-document.html
https://bookdown.org/yihui/bookdown/tables.html