style_header: style_header

View source: R/styles.R

style_headerR Documentation

style_header

Description

Set the style used for the header of the tablespan table.

Usage

style_header(
  tbl,
  background_color = "#ffffff",
  text_color = "#000000",
  font_size = NULL,
  bold = FALSE,
  italic = FALSE,
  openxlsx_style = NULL,
  gt_style = NULL
)

Arguments

tbl

tablespan table

background_color

hex code for the background color

text_color

hex code for the text color

font_size

font size

bold

set to TRUE for bold

italic

set to TRUE for italic

openxlsx_style

optional custom openxlsx style. When provided, all other arguments are ignored

gt_style

optional custom gt style. When provided, all other arguments are ignored

Details

The styling for openxlsx and gt works differently:

- openxlsx_style must be a style object created with openxlsx::createStyle. This style will then be applied to the header - gt_style must be a list of gt::tab_style objects to be applied to the table

Value

the tablespan table with added styles

Examples

library(tablespan)
library(dplyr)
data("mtcars")

# We want to report the following table:
summarized_table <- mtcars |>
  group_by(cyl, vs) |>
  summarise(N = n(),
            mean_hp = mean(hp),
            sd_hp = sd(hp),
            mean_wt = mean(wt),
            sd_wt = sd(wt))

# Create a tablespan:
tbl <- tablespan(data = summarized_table,
                 formula = Cylinder:cyl + Engine:vs ~
                   N +
                   (`Horse Power` = Mean:mean_hp + SD:sd_hp) +
                   (`Weight` = Mean:mean_wt + SD:sd_wt),
                 title = "Motor Trend Car Road Tests",
                 subtitle = "A table created with tablespan",
                 footnote = "Data from the infamous mtcars data set.")

tbl |>
  style_header(
    openxlsx_style = openxlsx::createStyle(
      fontSize = 8,
      fgFill = "#ffffff"),
    gt_style = list(gt::cell_text(size = 8))) |>
  as_gt()

tablespan documentation built on Sept. 10, 2025, 10:35 a.m.