rr-markdownhuxtable

Using huxtable labels in RMarkdown for PDF


I am using huxtable to display tables in RMarkdown for output: pdf_document.

When I put a label in the table

huxtable(mytable) %>%
set_label("tab:mylabel")

and then make a reference in the body text like

See Table \@ref(tab:mylabel) for more details

It displays "See Table @ref(tab:mylabel) for more details" rather than giving the table number.

This was covered for Bookdown in Huxtable package for R: How to correctly reference huxtables in bookdown?

Do I need some special option or other setting to make it work for a regular PDF document?


Solution

  • Seems so. The rmarkdown guide says you will need "a bookdown format" to use cross-referencing in that way. However, there's an alternative: use embedded TeX, rather than this rmarkdown format. A MWE:

    ```{r}
    hux("A huxtable") %>% 
          set_label("tab:foo") %>% 
          set_caption("You'll need a caption too")
      
    ```
    
    Here's a reference to \ref{tab:foo}.