Modify the way footnote marks are formatted. This can be performed for those
footnote marks that alight to the targeted text in cells in various locations
in the table or the footnote marks that appear in the table footer. A simple
specification string can be provided for either or both types of marks in
opt_footnote_spec()
. This function serves as a shortcut for using either
of tab_options(footnotes.spec_ref = {spec})
or
tab_options(footnotes.spec_ftr = {spec})
.
Arguments
- data
The gt table data object
obj:<gt_tbl>
// requiredThis is the gt table object that is commonly created through use of the
gt()
function.- spec_ref, spec_ftr
Specifications for formatting of footnote marks
scalar<character>
// default:NULL
(optional
)Specification of the footnote marks when behaving as footnote references and as marks in the footer section of the table. This is a string containing spec characters. The default is the spec string
"^i"
, which is superscript text set in italics.
Specification rules for the formatting of footnote marks
A footnote spec consists of a string containing control characters for formatting. Not every type of formatting makes sense for footnote marks so the specification is purposefully constrained to the following:
as superscript text (with the
"^"
control character) or regular-sized text residing on the baselinebold text (with
"b"
), italicized text (with"i"
), or unstyled text (don't use either of the"b"
or"i"
control characters)enclosure in parentheses (use
"("
/")"
) or square brackets (with"["
/"]"
)a period following the mark (using
"."
); this is most commonly used in the table footer
With the aforementioned control characters we could, for instance, format
the footnote marks to be superscript text in bold type with "^b"
. We might
want the marks in the footer to be regular-sized text in parentheses, so the
spec could be either "()"
or "(x)"
(you can optionally use "x"
as a
helpful placeholder for the marks).
Examples
Use a modified version of sp500
the dataset to create a gt table with
row labels. We'll add two footnotes using the tab_footnote()
function. We
can call opt_footnote_spec()
to specify that the marks of the footnote
reference should be superscripts in bold, and, the marks in the footer
section should be enclosed in parentheses.
sp500 |>
dplyr::filter(date >= "1987-10-14" & date <= "1987-10-25") |>
dplyr::select(date, open, close, volume) |>
dplyr::mutate(difference = close - open) |>
dplyr::mutate(change = (close - open) / open) |>
dplyr::mutate(day = vec_fmt_datetime(date, format = "E")) |>
dplyr::arrange(-dplyr::row_number()) |>
gt(rowname_col = "date") |>
fmt_currency() |>
fmt_number(columns = volume, suffixing = TRUE) |>
fmt_percent(columns = change) |>
cols_move_to_start(columns = day) |>
cols_width(
stub() ~ px(130),
day ~ px(50),
everything() ~ px(100)
) |>
tab_footnote(
footnote = "Commerce report on trade deficit.",
locations = cells_stub(rows = 1)
) |>
tab_footnote(
footnote = "Black Monday market crash, representing the greatest
one-day percentage decline in U.S. stock market history.",
locations = cells_body(columns = change, rows = change < -0.15)
) |>
opt_footnote_spec(spec_ref = "^xb", spec_ftr = "(x)")
See also
Other table option functions:
opt_align_table_header()
,
opt_all_caps()
,
opt_css()
,
opt_footnote_marks()
,
opt_horizontal_padding()
,
opt_interactive()
,
opt_row_striping()
,
opt_stylize()
,
opt_table_font()
,
opt_table_lines()
,
opt_table_outline()
,
opt_vertical_padding()