Provide a vector of sensible system fonts for use with gt tables
Source:R/helpers.R
default_fonts.Rd
The vector of fonts given by default_fonts()
can be safely used with a
gt table rendered as HTML since the font stack is expected to be
available across a wide set of systems. We can always specify additional
fonts to use and place them higher in precedence order, done through
prepending to this vector (i.e., this font stack should be placed after that
to act as a set of fallbacks).
This vector of fonts is useful when specifying font
values in the
cell_text()
function (itself usable in the tab_style()
and
tab_style_body()
functions). If using opt_table_font()
(which also has a
font
argument) we probably don't need to specify this vector of fonts since
that function prepends font names (this is handled by its add
option, which
is TRUE
by default).
Examples
Let's use the exibble
dataset to create a simple, two-column gt table
(keeping only the char
and time
columns). Attempting to modify the fonts
used for the time
column is much safer if default_fonts()
is appended to
the end of the font
listing in the cell_text()
call. What will happen,
since the "Comic Sansa"
and "Menloa"
fonts shouldn't exist, is that we'll
get the first available font from vector of fonts that default_fonts()
provides.
exibble |>
dplyr::select(char, time) |>
gt() |>
tab_style(
style = cell_text(
font = c("Comic Sansa", "Menloa", default_fonts())
),
locations = cells_body(columns = time)
)
See also
Other helper functions:
adjust_luminance()
,
cell_borders()
,
cell_fill()
,
cell_text()
,
cells_body()
,
cells_column_labels()
,
cells_column_spanners()
,
cells_footnotes()
,
cells_grand_summary()
,
cells_row_groups()
,
cells_source_notes()
,
cells_stub_grand_summary()
,
cells_stub_summary()
,
cells_stubhead()
,
cells_stub()
,
cells_summary()
,
cells_title()
,
currency()
,
escape_latex()
,
google_font()
,
gt_latex_dependencies()
,
html()
,
md()
,
pct()
,
px()
,
random_id()
,
stub()
,
system_fonts()