'Quarto table cross-reference gt

 ---
title: "example"
format: 
  pdf: 
    documentclass: article
editor: visual
---

Hello everyone i have a simple problem which is driving me crazy: I want cross reference a table created by a gt table using a caption. Here is my setup:

     ```{r}
library(tidyverse)
library(gt)
tbl_1 <- tribble(~x, ~y,
                 1, 2,
                 3, 4)

      ```

And lets say i want to create a table from tbl_1 and cross reference it later. Here is my attempt:

```{r}
#| label: tbl-table-1
#| tbl-cap: "table 1"

tbl_1 %>% gt()
```

This gives me:

compilation failed- error
Package array Error:  Illegal pream-token (\caption): `c' used.

See the array package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.227 \caption
              {\label{tbl-table-1}table 1 } 

see example.log for more information.   

And if i use the caption argument in the gt function it gives me nothing.

```{r}
#| label: tbl-table-1
tbl_1 %>% gt(caption = "table 1")

```

result

Does anyone know of a solution or perhaps im doing something wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source