Reputation: 3486
I am not sure I understand this part from the documentation
the table label for a code chunk with the label foo will be tab:foo
Say I have a RMarkdown chunck such as
```{r mytable, echo=FALSE}
kable(df, booktabs=T)
```
I would consider mytabel
as the label for the code chunck. That means I should be able to type a narrative that looks like:
This is my table \@ref(tab:mytable)
And the \@ref should reference the table number instead of the chucnk id. Instead I get a double (and clickable) ??
.What am I doing wrong?
Upvotes: 1
Views: 148
Reputation: 639
In the second paragraph of the documention:
Like figures, tables with captions will also be numbered and can be referenced.
So you want to cross-reference a table, you must specify the caption
argument.
You can create a empty RStudio project and or save following code as index.Rmd
file. Or download
https://github.com/yihui/bookdown-minimal and replace the content of index.Rmd
file with the following code. Then you can press Build Book
button in the Build
panel.
---
title: "A Book"
author: "Frida Gomam"
site: bookdown::bookdown_site
output:
bookdown::gitbook: default
---
# reference
This is my table \@ref(tab:mytable)
# table
```{r mytable, echo=TRUE}
knitr::kable(iris[1:10, ], booktabs=T, caption='A table of the first 10 rows of the mtcars data')
```
Upvotes: 2