Referencing a 'hand-made' table using bookdown package

前端 未结 3 1305
夕颜
夕颜 2021-01-01 20:31

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.

相关标签:
3条回答
  • 2021-01-01 20:51

    I solved this with the following:

    ```{r table2 , echo=FALSE, results='asis'}
      cat(' Table: \\label{tab:table2}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|')
    
    ```
    

    Table \ref{tab:table2} shows...

    0 讨论(0)
  • 2021-01-01 20:59

    I am joining the discussion a bit late, but I just wanted to share a working MWE (based on the earlier answers):

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

    Table @ref(tab:table2) shows...

    0 讨论(0)
  • 2021-01-01 21:02

    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|
    
    0 讨论(0)
提交回复
热议问题