Modify the options available in a table. These options are named by the components, the subcomponents, and the element that can adjusted.
tab_options(
data,
container.width = NULL,
container.height = NULL,
container.overflow.x = NULL,
container.overflow.y = NULL,
table.width = NULL,
table.layout = NULL,
table.align = NULL,
table.margin.left = NULL,
table.margin.right = NULL,
table.background.color = NULL,
table.additional_css = NULL,
table.font.names = NULL,
table.font.size = NULL,
table.font.weight = NULL,
table.font.style = NULL,
table.font.color = NULL,
table.font.color.light = NULL,
table.border.top.style = NULL,
table.border.top.width = NULL,
table.border.top.color = NULL,
table.border.right.style = NULL,
table.border.right.width = NULL,
table.border.right.color = NULL,
table.border.bottom.style = NULL,
table.border.bottom.width = NULL,
table.border.bottom.color = NULL,
table.border.left.style = NULL,
table.border.left.width = NULL,
table.border.left.color = NULL,
heading.background.color = NULL,
heading.align = NULL,
heading.title.font.size = NULL,
heading.title.font.weight = NULL,
heading.subtitle.font.size = NULL,
heading.subtitle.font.weight = NULL,
heading.padding = NULL,
heading.padding.horizontal = NULL,
heading.border.bottom.style = NULL,
heading.border.bottom.width = NULL,
heading.border.bottom.color = NULL,
heading.border.lr.style = NULL,
heading.border.lr.width = NULL,
heading.border.lr.color = NULL,
column_labels.background.color = NULL,
column_labels.font.size = NULL,
column_labels.font.weight = NULL,
column_labels.text_transform = NULL,
column_labels.padding = NULL,
column_labels.padding.horizontal = NULL,
column_labels.vlines.style = NULL,
column_labels.vlines.width = NULL,
column_labels.vlines.color = NULL,
column_labels.border.top.style = NULL,
column_labels.border.top.width = NULL,
column_labels.border.top.color = NULL,
column_labels.border.bottom.style = NULL,
column_labels.border.bottom.width = NULL,
column_labels.border.bottom.color = NULL,
column_labels.border.lr.style = NULL,
column_labels.border.lr.width = NULL,
column_labels.border.lr.color = NULL,
column_labels.hidden = NULL,
row_group.background.color = NULL,
row_group.font.size = NULL,
row_group.font.weight = NULL,
row_group.text_transform = NULL,
row_group.padding = NULL,
row_group.padding.horizontal = NULL,
row_group.border.top.style = NULL,
row_group.border.top.width = NULL,
row_group.border.top.color = NULL,
row_group.border.bottom.style = NULL,
row_group.border.bottom.width = NULL,
row_group.border.bottom.color = NULL,
row_group.border.left.style = NULL,
row_group.border.left.width = NULL,
row_group.border.left.color = NULL,
row_group.border.right.style = NULL,
row_group.border.right.width = NULL,
row_group.border.right.color = NULL,
row_group.default_label = NULL,
row_group.as_column = NULL,
table_body.hlines.style = NULL,
table_body.hlines.width = NULL,
table_body.hlines.color = NULL,
table_body.vlines.style = NULL,
table_body.vlines.width = NULL,
table_body.vlines.color = NULL,
table_body.border.top.style = NULL,
table_body.border.top.width = NULL,
table_body.border.top.color = NULL,
table_body.border.bottom.style = NULL,
table_body.border.bottom.width = NULL,
table_body.border.bottom.color = NULL,
stub.background.color = NULL,
stub.font.size = NULL,
stub.font.weight = NULL,
stub.text_transform = NULL,
stub.border.style = NULL,
stub.border.width = NULL,
stub.border.color = NULL,
stub.indent_length = NULL,
stub_row_group.font.size = NULL,
stub_row_group.font.weight = NULL,
stub_row_group.text_transform = NULL,
stub_row_group.border.style = NULL,
stub_row_group.border.width = NULL,
stub_row_group.border.color = NULL,
data_row.padding = NULL,
data_row.padding.horizontal = NULL,
summary_row.background.color = NULL,
summary_row.text_transform = NULL,
summary_row.padding = NULL,
summary_row.padding.horizontal = NULL,
summary_row.border.style = NULL,
summary_row.border.width = NULL,
summary_row.border.color = NULL,
grand_summary_row.background.color = NULL,
grand_summary_row.text_transform = NULL,
grand_summary_row.padding = NULL,
grand_summary_row.padding.horizontal = NULL,
grand_summary_row.border.style = NULL,
grand_summary_row.border.width = NULL,
grand_summary_row.border.color = NULL,
footnotes.background.color = NULL,
footnotes.font.size = NULL,
footnotes.padding = NULL,
footnotes.padding.horizontal = NULL,
footnotes.border.bottom.style = NULL,
footnotes.border.bottom.width = NULL,
footnotes.border.bottom.color = NULL,
footnotes.border.lr.style = NULL,
footnotes.border.lr.width = NULL,
footnotes.border.lr.color = NULL,
footnotes.marks = NULL,
footnotes.multiline = NULL,
footnotes.sep = NULL,
source_notes.background.color = NULL,
source_notes.font.size = NULL,
source_notes.padding = NULL,
source_notes.padding.horizontal = NULL,
source_notes.border.bottom.style = NULL,
source_notes.border.bottom.width = NULL,
source_notes.border.bottom.color = NULL,
source_notes.border.lr.style = NULL,
source_notes.border.lr.width = NULL,
source_notes.border.lr.color = NULL,
source_notes.multiline = NULL,
source_notes.sep = NULL,
row.striping.background_color = NULL,
row.striping.include_stub = NULL,
row.striping.include_table_body = NULL,
page.orientation = NULL,
page.numbering = NULL,
page.header.use_tbl_headings = NULL,
page.footer.use_tbl_notes = NULL,
page.width = NULL,
page.height = NULL,
page.margin.left = NULL,
page.margin.right = NULL,
page.margin.top = NULL,
page.margin.bottom = NULL,
page.header.height = NULL,
page.footer.height = NULL
)An object of class gt_tbl.
A table object that is created using the gt() function.
The width and height of the table's
container. Can be specified as a single-length character with units of
pixels or as a percentage. If provided as a single-length numeric vector,
it is assumed that the value is given in units of pixels. The px() and
pct() helper functions can also be used to pass in numeric values and
obtain values as pixel or percent units.
Options to enable scrolling
in the horizontal and vertical directions when the table content overflows
the container dimensions. Using TRUE (the default for both) means that
horizontal or vertical scrolling is enabled to view the entire table in
those directions. With FALSE, the table may be clipped if the table width
or height exceeds the container.width or container.height.
The width of the table. Can be specified as a
single-length character with units of pixels or as a percentage. If
provided as a single-length numeric vector, it is assumed that the value is
given in units of pixels. The px() and pct() helper functions can also
be used to pass in numeric values and obtain values as pixel or percent
units.
The value for the table-layout CSS style in the HTML
output context. By default, this is "fixed" but another valid option is
"auto".
The horizontal alignment of the table in its container. By
default, this is "center". Other options are "left" and "right". This
will automatically set table.margin.left and table.margin.right to the
appropriate values.
The size of the margins on the
left and right of the table within the container. Can be specified as a
single-length character with units of pixels or as a percentage. If
provided as a single-length numeric vector, it is assumed that the value is
given in units of pixels. The px() and pct() helper functions can also
be used to pass in numeric values and obtain values as pixel or percent
units. Using table.margin.left or table.margin.right will overwrite any
values set by table.align.
Background colors for the parent element table and the following child
elements: heading, column_labels, row_group, stub, summary_row,
grand_summary_row, footnotes, and source_notes. A color name or a
hexadecimal color code should be provided.
This option can be used to supply an additional block of CSS rules to be applied after the automatically generated table CSS.
The names of the fonts used for the table. This is a vector of several font names. If the first font isn't available, then the next font is tried (and so on).
The font sizes for the parent text element table and the following child
elements: heading.title, heading.subtitle, column_labels,
row_group, footnotes, and source_notes. Can be specified as a
single-length character vector with units of pixels (e.g., 12px) or as a
percentage (e.g., 80\%). If provided as a single-length numeric vector,
it is assumed that the value is given in units of pixels. The px() and
pct() helper functions can also be used to pass in numeric values and
obtain values as pixel or percentage units.
The font weights of the table, heading.title, heading.subtitle,
column_labels, row_group, and stub text elements. Can be a text-based
keyword such as "normal", "bold", "lighter", "bolder", or, a
numeric value between 1 and 1000, inclusive. Note that only variable
fonts may support the numeric mapping of weight.
The font style for the table. Can be one of either
"normal", "italic", or "oblique".
The text color used throughout the table. There are two variants:
table.font.color is for text overlaid on lighter background colors, and
table.font.color.light is automatically used when text needs to be
overlaid on darker background colors. A color name or a hexadecimal color
code should be provided.
The style, width, and color properties of the table's absolute top and absolute bottom borders.
Controls the horizontal alignment of the heading title
and subtitle. We can either use "center", "left", or "right".
The amount of vertical padding to incorporate in the heading (title and
subtitle), the column_labels (this includes the column spanners), the row
group labels (row_group.padding), in the body/stub rows
(data_row.padding), in summary rows (summary_row.padding or
grand_summary_row.padding), or in the footnotes and source notes
(footnotes.padding and source_notes.padding).
The amount of horizontal padding to incorporate in the heading (title and
subtitle), the column_labels (this includes the column spanners), the row
group labels (row_group.padding.horizontal), in the body/stub rows
(data_row.padding), in summary rows (summary_row.padding.horizontal or
grand_summary_row.padding.horizontal), or in the footnotes and source
notes (footnotes.padding.horizontal and
source_notes.padding.horizontal).
The style, width, and color properties of the header's bottom border. This
border shares space with that of the column_labels location. If the
width of this border is larger, then it will be the visible border.
The style, width, and color properties for the left and right borders of
the heading location.
Options to apply text transformations to the column_labels, row_group,
stub, summary_row, and grand_summary_row text elements. Either of the
"uppercase", "lowercase", or "capitalize" keywords can be used.
The style, width, and color properties for all vertical lines ('vlines')
of the the column_labels.
The style, width, and color properties for the top border of the
column_labels location. This border shares space with that of the
heading location. If the width of this border is larger, then it will
be the visible border.
The style, width, and color properties for the bottom border of the
column_labels location.
The style, width, and color properties for the left and right borders of
the column_labels location.
An option to hide the column labels. If providing
TRUE then the entire column_labels location won't be seen and the table
header (if present) will collapse downward.
The style, width, and color properties for all top, bottom, left, and right
borders of the row_group location.
An option to set a default row group label for
any rows not formally placed in a row group named by group in any call of
tab_row_group(). If this is set as NA_character and there are rows that
haven't been placed into a row group (where one or more row groups already
exist), those rows will be automatically placed into a row group without a
label.
How should row groups be structured? By default,
they are separate rows that lie above the each of the groups. Setting this
to TRUE will structure row group labels are columns to the far left of
the table.
The style, width, and color properties for all horizontal lines ('hlines')
and vertical lines ('vlines') in the table_body.
The style, width, and color properties for all top and bottom borders of
the table_body location.
The style, width, and color properties for the vertical border of the table stub.
The width of each indentation level. By default
this is "5px".
Options for the row group column in the stub (made possible when using
row_group.as_column = TRUE). The defaults for these options mirror that
of the stub.* variants (except for stub_row_group.border.width, which
is "1px" instead of "2px").
The style, width, and color properties for all horizontal borders of the
summary_row location.
The style, width, and color properties for the top borders of the
grand_summary_row location.
The style, width, and color properties for the bottom border of the
footnotes location.
The style, width, and color properties for the left and right borders of
the footnotes location.
The set of sequential marks used to reference and
identify each of the footnotes (same input as the opt_footnote_marks()
function. We can supply a vector that represents the series of footnote
marks. This vector is recycled when its usage goes beyond the length of the
set. At each cycle, the marks are simply combined (e.g., * -> ** ->
***). The option exists for providing keywords for certain types of
footnote marks. The keyword "numbers" (the default, indicating that we
want to use numeric marks). We can use lowercase "letters" or uppercase
"LETTERS". There is the option for using a traditional symbol set where
"standard" provides four symbols, and, "extended" adds two more
symbols, making six.
An option to either put
footnotes and source notes in separate lines (the default, or TRUE) or
render them as a continuous line of text with footnotes.sep providing the
separator (by default " ") between notes.
The separating characters between
adjacent footnotes and source notes in their respective footer sections
when rendered as a continuous line of text (when
footnotes.multiline == FALSE). The default value is a single space
character (" ").
The style, width, and color properties for the bottom border of the
source_notes location.
The style, width, and color properties for the left and right borders of
the source_notes location.
The background color for striped table body rows. A color name or a hexadecimal color code should be provided.
An option for whether to include the stub when striping rows.
An option for whether to include the table body when striping rows.
For RTF output, this provides an two options for page
orientation: "portrait" (the default) and "landscape".
Within RTF output, should page numbering be displayed?
By default, this is set to FALSE but if TRUE then page numbering text
will be added to the document header.
If TRUE then RTF output tables will
migrate all table headings (including the table title and all column
labels) to the page header. This page header content will repeat across
pages. By default, this is FALSE.
If TRUE then RTF output tables will
migrate all table footer content (this includes footnotes and source notes)
to the page footer. This page footer content will repeat across pages. By
default, this is FALSE.
The page width and height in the standard
portrait orientation. This is for RTF table output and the default
values (in inches) are 8.5in and 11.0in.
For RTF table output, these options correspond to the left, right, top, and
bottom page margins. The default values for each of these is 1.0in.
The heights of the page header
and footer for RTF table outputs. Default values for both are 0.5in.
Use exibble to create a gt table with all the main parts added. We
can use this gt object going forward to demo some of what's available in
the tab_options() function.
tab_1 <-
exibble %>%
dplyr::select(-c(fctr, date, time, datetime)) %>%
gt(
rowname_col = "row",
groupname_col = "group"
) %>%
tab_header(
title = md("Data listing from **exibble**"),
subtitle = md("`exibble` is an R dataset")
) %>%
fmt_number(columns = num) %>%
fmt_currency(columns = currency) %>%
tab_footnote(
footnote = "Using commas for separators.",
locations = cells_body(
columns = num,
rows = num > 1000
)
) %>%
tab_footnote(
footnote = "Using commas for separators.",
locations = cells_body(
columns = currency,
rows = currency > 1000
)
) %>%
tab_footnote(
footnote = "Alphabetical fruit.",
locations = cells_column_labels(columns = char)
)tab_1

Modify the table width to be 100% (which spans the entire content width area).
tab_1 %>% tab_options(table.width = pct(100))

Modify the table's background color to be "lightcyan".
tab_1 %>% tab_options(table.background.color = "lightcyan")

Use letters as the marks for footnote references. Also, separate footnotes in the footer by spaces instead of newlines.
tab_1 %>%
tab_options(
footnotes.marks = letters,
footnotes.multiline = FALSE
)

Change the padding of data rows to 5 px.
tab_1 %>%
tab_options(
data_row.padding = px(5)
)

Reduce the size of the title and the subtitle text.
tab_1 %>%
tab_options(
heading.title.font.size = "small",
heading.subtitle.font.size = "small"
)

2-10
Other part creation/modification functions:
tab_footnote(),
tab_header(),
tab_row_group(),
tab_source_note(),
tab_spanner_delim(),
tab_spanner(),
tab_stub_indent(),
tab_stubhead(),
tab_style()