Cross-referencing tables generated by RStudio Preview version

Loving the new visual markdown editor feature in RStudio preview release (1.4.869). The table editor is really useful for quickly generating text-heavy tables. I'm struggling to cross reference the simple tables generated by RStudio though. Here's a sample output generated by RStudio: when I knit this it correctly generates the table caption and numbers the table accordingly. But, I can't figure out how to then cross reference that generated table, e.g. what would normally be "See Table.\@ref(tab:my-table)" when the table is generated in a chunk with name "my-table". Since the table is being numbered correctly it seems like it must be possible?

| Col1 | Col2 | Col3 |
|------|------|------|
|    a  |    b  |    c  |
|   d   |    e  |   f   |
|    g  |   h   |   i   |

Table: Test

You can write this

---
title: Referencing table
output: bookdown::html_document2
---

| Col1 | Col2 | Col3 |
|------|------|------|
| a    | b    | c    |
| d    | e    | f    |
| g    | h    | i    |

: (\#tab:test) A caption Test

See table \@ref(tab:test)

You need to use a bookdown format to make the referencing work. See https://rstudio.github.io/visual-markdown-editing/#/technical?id=cross-references

The key is using (\#tab:label) in source mode or (#tab:label) in visual editor mode so thate the reference is found.

Thanks for the quick reply, I can confirm that that solves it when knitting to pdf, word, and html using bookdown

Seems like this would be good to add to the bookdown documentation, particularly given the likely increase in these kinds of tables that the visual editor will create, I can take a stab at one

Where exactly do you suggest to add something ?

I suppose here:

:sweat_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.