Search code examples
rgt

Add Caption to table


I want to caption the table at the top/bottom of a table. Is there a caption function in the gt package?

 gt(head(mtcars)) %>%
        tab_header(title="", subtitle="Table 1: Mtcars with gt.") %>%
        tab_options(table.width=pct(90),
                        table.border.top.style=0,
                        row.padding=px(4)) %>%
            tab_style(style=cells_styles(
                          text_align='left',
                          text_color='grey'),
                  locations=cells_title(groups="subtitle"))

Solution

  • I could get the caption argument by installing the development version of the package from Github.

    #devtools::install_github("rstudio/gt")
    library(gt)
    
    gt(head(mtcars), caption = 'This is table caption') %>%
      tab_header(title="A", subtitle="Table 1: Mtcars with gt.")
    

    enter image description here