google_font | R Documentation |
The google_font()
helper function can be used wherever a font name should
be specified. There are two instances where this helper can be used: the
name
argument in opt_table_font()
(for setting a table font) and in that
of cell_text()
(used with tab_style()
). To get a helpful listing of fonts
that work well in tables, use the info_google_fonts()
function.
google_font(name)
name |
Google Font name
The complete name of a font available in Google Fonts. |
An object of class font_css
.
Use the exibble
dataset to create a gt table of two columns and eight
rows. We'll replace missing values with em dashes using the sub_missing()
function. For text in the time
column, we will use the font called "IBM Plex Mono"
which is available in Google Fonts. This is defined in the
google_font()
function call, itself part of a vector that includes fonts
returned by the default_fonts()
function (those fonts will serve as
fallbacks just in case the font supplied by Google Fonts is not accessible).
In terms of placement, all of this is given to the font
argument of the
cell_text()
helper function which is itself given to the style
argument
of tab_style()
.
exibble |> dplyr::select(char, time) |> gt() |> sub_missing() |> tab_style( style = cell_text( font = c( google_font(name = "IBM Plex Mono"), default_fonts() ) ), locations = cells_body(columns = time) )
We can use a subset of the sp500
dataset to create a small gt table.
With fmt_currency()
, we can display a dollar sign for the first row of the
monetary values. Then, we'll set a larger font size for the table and opt to
use the "Merriweather"
font by calling google_font()
within
opt_table_font()
. In cases where that font may not materialize, we include
two font fallbacks: "Cochin"
and the catchall "Serif"
group.
sp500 |> dplyr::slice(1:10) |> dplyr::select(-volume, -adj_close) |> gt() |> fmt_currency( rows = 1, currency = "USD", use_seps = FALSE ) |> tab_options(table.font.size = px(20)) |> opt_table_font( font = list( google_font(name = "Merriweather"), "Cochin", "Serif" ) )
8-30
v0.2.2
(August 5, 2020)
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()
,
cells_stub_grand_summary()
,
cells_stub_summary()
,
cells_stubhead()
,
cells_summary()
,
cells_title()
,
currency()
,
default_fonts()
,
escape_latex()
,
from_column()
,
gt_latex_dependencies()
,
html()
,
md()
,
nanoplot_options()
,
pct()
,
px()
,
random_id()
,
stub()
,
system_fonts()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.