This helper function adds whitespace to numeric values so that they can
be aligned on the decimal without requiring additional trailing zeroes.
This function is intended to use within the gt::fmt()
function.
See also
Other Utilities:
add_text_img()
,
fa_icon_repeat()
,
fmt_pad_num()
,
fmt_pct_extra()
,
fmt_symbol_first()
,
generate_df()
,
gt_add_divider()
,
gt_badge()
,
gt_double_table()
,
gt_duplicate_column()
,
gt_fa_rank_change()
,
gt_fa_rating()
,
gt_highlight_cols()
,
gt_highlight_rows()
,
gt_img_border()
,
gt_img_circle()
,
gt_img_multi_rows()
,
gt_img_rows()
,
gt_index()
,
gt_merge_stack()
,
gt_merge_stack_color()
,
gt_two_column_layout()
,
gtsave_extra()
,
img_header()
,
tab_style_by_grp()
Examples
library(gt)
padded_tab <- data.frame(x = c(1.2345, 12.345, 123.45, 1234.5, 12345)) %>%
gt() %>%
fmt(fns = function(x) {
pad_fn(x, nsmall = 4)
}) %>%
tab_style(
# MUST USE A MONO-SPACED FONT
# https://fonts.google.com/?category=Monospace
style = cell_text(font = google_font("Fira Mono")),
locations = cells_body(columns = x)
)