MS Word 中的 RMarkdown、居中和引用 table

RMarkdown, Centre and reference table in MS Word

我正在使用 R Markdown 并尝试生成 table 并将其居中放置在 word 文档中。下面是我从 github 中提取的代码作为测试

Table \@ref(tab:table-single) is a simple example.

```{r table-single, tidy=FALSE}
knitr::kable(
  head(mtcars, 10), booktabs = TRUE,
  caption = 'A table of the first 10 rows of the mtcars data.'
)
```

当我 运行 这段代码时, table 名称永远不会解析,所以我得到 \@ref(tab:table-single) 而不是 Table 2.1从最后可以看出document

我正在编织 MS Word

谢谢

如果您使用 bookdown 包来呈现您的降价,您将获得适当的交叉引用:

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

Table \@ref(tab:table-single) is a simple example.

```{r table-single, tidy=FALSE}
knitr::kable(
  head(mtcars, 10), booktabs = TRUE,
  caption = 'A table of the first 10 rows of the mtcars data.'
)
```