【问题标题】:reference a markdown table in R markdown在 R markdown 中引用 markdown 表
【发布时间】:2019-12-10 17:59:53
【问题描述】:

我的问题是如何引用如下降价格式的表格,因为这里的答案不起作用 Referencing a 'hand-made' table using bookdown package 我试过了

---
output: html_document
---

you may refer to this table using \@ref(tab:foo)

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

+-----------------------+-----------------------+-----------------------+
| Auteur                | Protocole             | Résultats             |
+=======================+=======================+=======================+
| (Jiayi 2011)          | Analyse formantique   | Diphtongaison de [e  |
+-----------------------+-----------------------+-----------------------+

它没有工作。

它给出了“表格:(#tab:foo) 你的表格标题。”作为标题和“您可以使用@ref(tab:foo) 引用此表”如果我使用@ref(tab:foo) 交叉引用。

是否也可以自动编号?

【问题讨论】:

标签: r-markdown


【解决方案1】:

看来您只需要使用 bookdown 的 output formats

---
output:
  bookdown::html_document2:
    df_print: paged
---

you may refer to this table using \@ref(tab:foo)

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

+-----------------------+-----------------------+-----------------------+
| Auteur                | Protocole             | Résultats             |
+=======================+=======================+=======================+
| (Jiayi 2011)          | Analyse formantique   | Diphtongaison de [e  |
+-----------------------+-----------------------+-----------------------+

【讨论】:

  • 它有效!太感谢了。顺便问一下,你知道如何让标题出现在表格下方而不是上方吗?
  • 太棒了!我认为普遍的共识是表格标题应该在表格上方(例如this discussion)。如果需要,也许可以提出一个新问题。
【解决方案2】:

这里的答案对我有用:

我加入讨论有点晚了,但我只是想分享一个有效的 MWE(基于早期的答案):

```{r , echo=FALSE, results='asis'}
  cat(' Table: (\\#tab:mwe) Example

  | 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 中的\@ref(tab:mwe) 引用该表。这在 pdf 和 html 导出中对我有用。

请注意,如果您想添加希腊字母或更复杂的子或上标,则需要在代码块之外包含以下文本参考


(ref:flower) Flower~dimensions\ example~


```{r , echo=FALSE, results='asis'}
  cat(' Table: (\\#tab:mwe) Example with (ref:flower)

  | 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|')```

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-31
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    相关资源
    最近更新 更多