Toggles standard whitespace to non-breaking spaces (\u00A0) dynamically in all visible statistics columns of a gtsummary table's body (or vice versa). This forces the layout engine to keep statistics (e.g., "12.5 ( 95%)") on a single line when protected. Column headers and labels remain unaffected. For the rare cases when protecting creates ugly squashed label column protection can be reversed using the same function.

adjust_stat_columns_wrap(tbl, mode = c("protect", "unprotect"))

Arguments

tbl

(gtsummary)
A gtsummary object.

mode

(character(1))
Either "protect" (replaces whitespace with non-breaking spaces) or "unprotect" (replaces non-breaking spaces with standard spaces). Defaults to "protect".

Value

A modified gtsummary object.

Examples

tbl <- gtsummary::tbl_summary(
  trial,
  by = trt,
  include = c(age, grade)
)
adjust_stat_columns_wrap(tbl, "protect")
Characteristic Drug A
N = 98
1
Drug B
N = 102
1
Age 46 (37, 60) 48 (39, 56)
    Unknown 7 4
Grade

    I 35 (36%) 33 (32%)
    II 32 (33%) 36 (35%)
    III 31 (32%) 33 (32%)
1 Median (Q1, Q3); n (%)