使用Bookdown包引用“手工制作"表 [英] Referencing a 'hand-made' table using bookdown package

查看:85
本文介绍了使用Bookdown包引用“手工制作"表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 bookdown 包引用一个表.在表文档中,作者仅显示了如何使用knitr::kable创建表.

I'm trying to reference a table using the bookdown package. In the documentation for tables, the author only shows how to create tables using knitr::kable.

```{r table1}
knitr::kable(
  head(iris, 20), caption = 'Here is a nice table!',
  booktabs = TRUE
)
```

\@ref(tab:table1)在这里.

使用knitr::kable可以正常工作.显示该表的标题,我可以参考该表.我想对经典的手工Markdown表执行相同的操作,但是显然下面的代码失败了. 如何获得与上面的代码相似的结果?

Using knitr::kable works just fine. The caption of the table is displayed and I can reference the table. I would like to do the same with a classic, hand-made markdown table, but obviously the code below fails. What can I do to get a similar result as with the code above?

```{r table2, echo=FALSE, results='asis'}
cat('| Sepal.Length| Sepal.Width| Petal.Length|
|------------:|-----------:|------------:|
|          5.1|         3.5|          1.4|
|          4.9|         3.0|          1.4|
|          4.7|         3.2|          1.3|
|          4.6|         3.1|          1.5|')
```

\@ref(tab:table2)在这里.

这张图片显示了该代码在编织时的输出.

This picture shows the output of this code when it is knitted.

推荐答案

我在文档中确实提到了它,但可能还不够清楚.我说过您需要格式为(\#tab:...)的标签.例如,您可以使用\@ref(tab:foo)引用此表.

I did mention it in the documentation, but perhaps it is not clear enough. I said you need the label of the form (\#tab:...). For example, you may refer to this table using \@ref(tab:foo).

Table: (\#tab:foo) Your table caption.

| Sepal.Length| Sepal.Width| Petal.Length|
|------------:|-----------:|------------:|
|          5.1|         3.5|          1.4|
|          4.9|         3.0|          1.4|
|          4.7|         3.2|          1.3|
|          4.6|         3.1|          1.5|

这篇关于使用Bookdown包引用“手工制作"表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆