Is it possible to change the font of the caption in the gt package in R? I am working with a specific format, and I need to make the font of the caption Arial, while the rest of the table needs to be in Georgia. Here is a same of the code that I am working with:
library(gt)
DF <- tibble(character = c('a', 'b', 'c'),
value = round(runif(3, 4, 7)))
DF %>%
gt() %>%
tab_options(table.font.names = 'Georgia',
column_labels.font.weight = 'bold',
heading.title.font.size = 14,
heading.subtitle.font.size = 14,
table.font.color = 'steelblue',
source_notes.font.size = 10,
#source_notes.
table.font.size = 14) %>%
# Adjust title font
tab_style(
style = list(
cell_text(
align = "left",
weight = 'bold',
)
),
locations = list(
cells_title(groups = c("title"))
)
) %>%
# Adjust title font
tab_style(
style = list(
cell_text(
align = "left",
)
),
locations = list(
cells_title(groups = c("subtitle"))
)
) %>%
tab_header(
title = md("title"),
subtitle = md("subtitle")
) %>%
tab_source_note(
source_note = md("caption")
)```
You can pass html in source_note in which you can specify font-family as css property.
library(gt)
DF <- tibble(character = c('a', 'b', 'c'),
value = round(runif(3, 4, 7)))
DF %>%
gt() %>%
tab_options(table.font.names = 'Georgia',
column_labels.font.weight = 'bold',
heading.title.font.size = 14,
heading.subtitle.font.size = 14,
table.font.color = 'steelblue',
source_notes.font.size = 10,
#source_notes.
table.font.size = 14) %>%
# Adjust title font
tab_style(
style = list(
cell_text(
align = "left",
weight = 'bold',
)
),
locations = list(
cells_title(groups = c("title"))
)
) %>%
# Adjust title font
tab_style(
style = list(
cell_text(
align = "left",
)
),
locations = list(
cells_title(groups = c("subtitle"))
)
) %>%
tab_header(
title = md("title"),
subtitle = md("subtitle")
) %>%
tab_source_note(
source_note = html('<p style="font-family:Arial">caption</p>')
)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With