This function takes a gt table and applies custom formatting. It allows you to align columns, apply bold text to certain rows, and adjust column widths if specified.

custom_format(gt_table, align = "right", column_size = NULL)

Arguments

gt_table

A gt table object (also handles gtsummary tables by converting them).

align

A character string defining the alignment of specific columns. Passed to the gt::cols_align() function (e.g., "left", "right", "center"). Default is "right".

column_size

A named list or vector defining the width of columns (optional). The list should specify the width for one or more columns. If not provided, column widths will not be modified.

Value

A gt table object with the specified formatting applied. The table will have columns aligned according to the align parameter, and cells in the "label" rows will have bold text. If column_size is provided, the column widths will be adjusted accordingly.

Examples

# Example usage
tbl <- RastaRocket::desc_var(iris,
  table_title = "test",
  group = TRUE,
  var_group = "Species")
#> Note: 'var_group' is provided but 'by_group = FALSE'. The grouping variable will be ignored.
formatted_tbl <- custom_format(tbl,
  align = "center",
  column_size = list(label ~ gt::pct(50)))
formatted_tbl
test
Characteristic N Overall
Sepal.Length 150
    Mean (SD)
5.8 (0.8)
    Median (Q1 ; Q3)
5.8 (5.1 ; 6.4)
    Min ; Max
4.3 ; 7.9
Sepal.Width 150
    Mean (SD)
3.1 (0.4)
    Median (Q1 ; Q3)
3.0 (2.8 ; 3.3)
    Min ; Max
2.0 ; 4.4
Petal.Length 150
    Mean (SD)
3.8 (1.8)
    Median (Q1 ; Q3)
4.4 (1.6 ; 5.1)
    Min ; Max
1.0 ; 6.9
Petal.Width 150
    Mean (SD)
1.2 (0.8)
    Median (Q1 ; Q3)
1.3 (0.3 ; 1.8)
    Min ; Max
0.1 ; 2.5