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
)
```
Table \@ref(tab:table1)
is here.
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|')
```
Table \@ref(tab:table2)
is here.
This picture shows the output of this code when it is knitted.