Cross-referencing is available in a branch version of gt and it looks like it's coming soon to the master version. There's an open issue asking for cross-referencing at the gt repository on github, as well as a pull request with code that implements cross-referencing.
Here's an example:*
First, install the version of the package with the cross-referencing updates in the pull request.
devtools::install_github("rstudio/gt", ref="eff3be7384365a44459691e49b9b740420cd0851")
Below is an rmarkdown document demonstrating cross-referencing with gt. The new label argument in tab_header is the cross-referencing label.
---
output:
bookdown::pdf_document2
toc: FALSE
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(knitr)
library(gt)
```
You can see in Table \@ref(tab:tab1) that this is the famous `mtcars` data frame.
```{r}
mtcars %>%
slice(1:2) %>%
gt() %>%
tab_header(title="First two rows of mtcars",
label="tab:tab1")
```
The PDF output is below. Note that the title text is in a larger font size than the Table 1:. Maybe this can be changed with some title formatting commands, but it would be nice to have gt output the entire caption in the same font size.
* I initially wasn't able to get cross-referencing to work, but Vincent Aral-Bundock provided the proper label syntax at github in response to my query.