手册“Bookdown:使用 R Markdown 创作书籍和技术文档”教授如何使用 knit::kable 呈现表格,从而获得表格的自动编号(以及其他好处)。 p>
还可以使用 R Markdown 代码手动创建简单的表格,非常容易阅读和编辑。
问题:如何使用 knitr::kable 呈现这样一个手动创建的表格?
请参阅下面的 MWE,它是在 R Markdown/Bookdown 项目中编写的:
---
documentclass: book
output:
bookdown::gitbook: default
---
# Just a test
With knitr::kable, I have references to automatically numbered tables. Such as Table \@ref(tab:table1).
```{r table1, tidy=FALSE, echo=FALSE}
knitr::kable(
head(mtcars[, 1:2], 2), booktabs = TRUE,
caption = 'Test table 1.'
)
```
<br>
In my project, I manually create tables with R Markdown code. However, I dont know how to:
1. express this manually created table with knitr::kable, and
2. thus get automatic numbering to the table.
See an example of a manually entered table below. Problems: no numbering, and how to refer to it?
<br>
Table: Manually entered data in a simple table - easy to read, easy to edit as R Markdown code.
Column 1 Column 2
------------- ---------
lorem ipsum
dolor sit
最佳答案
您可以手动完成:
---
documentclass: book
output:
bookdown::gitbook: default
---
# Just a test
With knitr::kable, I have references to automatically numbered tables. Such as Table \@ref(tab:table1).
```{r table1, tidy=FALSE, echo=FALSE}
knitr::kable(
head(mtcars[, 1:2], 2), booktabs = TRUE,
caption = 'Test table 1.'
)
```
<br>
Such as Table <a href="#tab:table2">1.2</a>.</p>.
In my project, I manually create tables with R Markdown code. However, I dont know how to:
1. express this manually created table with knitr::kable, and
2. thus get automatic numbering to the table.
See an example of a manually entered table below. Problems: no numbering, and how to refer to it?
<br>
<table>
<caption><span id="tab:table2">Table 1.2: </span>Test table 2.</caption>
Column 1 Column 2
------------- ---------
lorem ipsum
dolor sit
</table>
关于r - 如何手动创建一个简单的表格并用knitr呈现它:kable in R Markdown (more precisely: in Bookdown)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70565733/