将标题添加到表格

时间:2021-05-09 02:43:00

标签: r gt

我想在表格的顶部/底部为表格添加标题。 caption 包中是否有 function gt

 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"))

1 个答案:

答案 0 :(得分:1)

我可以通过从 Github 安装包的开发版本来获取 caption 参数。

#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