【问题标题】:How to generate automatic numbering of table titles in word using knit in Rmarkdown?如何使用 Rmarkdown 中的 knit 在 word 中生成表格标题的自动编号?
【发布时间】:2020-11-18 15:38:30
【问题描述】:

我正在为我的工作做一份降价报告。我需要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"))

【问题讨论】:

    标签: r r-markdown word


    【解决方案1】:

    为此,您需要使用 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

    【讨论】:

      猜你喜欢
      • 2017-06-18
      • 1970-01-01
      • 2019-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-30
      • 1970-01-01
      相关资源
      最近更新 更多