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.align = NULL, table.margin.left = NULL,
  table.margin.right = NULL, table.font.size = NULL,
  table.background.color = NULL, table.border.top.style = NULL,
  table.border.top.width = NULL, table.border.top.color = NULL,
  heading.background.color = NULL, heading.title.font.size = NULL,
  heading.subtitle.font.size = NULL,
  heading.border.bottom.style = NULL,
  heading.border.bottom.width = NULL,
  heading.border.bottom.color = NULL,
  column_labels.background.color = NULL,
  column_labels.font.size = NULL, column_labels.font.weight = NULL,
  column_labels.hidden = NULL, row_group.background.color = NULL,
  row_group.font.size = NULL, row_group.font.weight = 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,
  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, row.padding = NULL,
  summary_row.background.color = NULL, summary_row.padding = NULL,
  summary_row.text_transform = NULL,
  grand_summary_row.background.color = NULL,
  grand_summary_row.padding = NULL,
  grand_summary_row.text_transform = NULL, footnote.sep = NULL,
  footnote.marks = NULL, footnote.font.size = NULL,
  footnote.padding = NULL, sourcenote.font.size = NULL,
  sourcenote.padding = NULL, row.striping.include_stub = NULL,
  row.striping.include_table_body = NULL)

Arguments

data

A table object that is created using the gt() function.

container.width, container.height

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.

container.overflow.x, container.overflow.y

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.

table.width

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.

table.align

The 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.

table.margin.left, table.margin.right

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.

table.font.size, heading.title.font.size, heading.subtitle.font.size, column_labels.font.size, row_group.font.size, footnote.font.size, sourcenote.font.size

Font sizes for the parent text element table and the following child elements: heading.title, heading.subtitle, columns, row_group, footnote, and sourcenote. 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 percent units.

table.background.color, heading.background.color, column_labels.background.color, row_group.background.color, summary_row.background.color, grand_summary_row.background.color

background colors for the parent element table and the following child elements: heading, columns, row_group, summary_row, and table_body. A color name or a hexadecimal color code should be provided.

table.border.top.style, table.border.top.width, table.border.top.color

The style, width, and color of the table's top border.

heading.border.bottom.style, heading.border.bottom.width, heading.border.bottom.color

The style, width, and color of the heading's bottom border.

column_labels.font.weight, row_group.font.weight

the font weight of the columns and row_group text element.

column_labels.hidden

An option to hide the column labels.

row_group.border.top.style, row_group.border.top.width, row_group.border.top.color

The style, width, and color of the row group's top border.

row_group.border.bottom.style, row_group.border.bottom.width, row_group.border.bottom.color

The style, width, and color of the row group's bottom border.

table_body.border.top.style, table_body.border.top.width, table_body.border.top.color

The style, width, and color of the table body's top border.

table_body.border.bottom.style, table_body.border.bottom.width, table_body.border.bottom.color

the style, width, and color of the table body's bottom border.

row.padding, summary_row.padding, grand_summary_row.padding

the amount of padding in each row and in each type of summary row.

summary_row.text_transform, grand_summary_row.text_transform

an option to apply text transformations to the label text in each summary row.

footnote.sep

the separating characters between adjacent footnotes in the footnotes section. The default value produces a linebreak.

footnote.marks

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.

footnote.padding, sourcenote.padding

The amount of padding to apply to the footnote and source note sections.

row.striping.include_stub

An option for whether to include the stub when striping rows.

row.striping.include_table_body

An option for whether to include the table body when striping rows.

Value

an object of class gt_tbl.

Figures

See also

Other table-part creation/modification functions: gt_preview, gt, tab_footnote, tab_header, tab_row_group, tab_source_note, tab_spanner, tab_stubhead, tab_style

Examples

# Use `exibble` to create a gt table with # all the main parts added; we can use this # going forward to demo some `tab_options()` 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 = vars(num)) %>% fmt_currency(columns = vars(currency)) %>% tab_footnote( footnote = "Using commas for separators.", locations = cells_data( columns = vars(num), rows = num > 1000) ) %>% tab_footnote( footnote = "Using commas for separators.", locations = cells_data( columns = vars(currency), rows = currency > 1000) ) %>% tab_footnote( footnote = "Alphabetical fruit.", locations = cells_column_labels( columns = vars(char)) ) # Modify the table width to 100% (which # spans the entire content width area) tab_2 <- tab_1 %>% tab_options( table.width = pct(100) ) # Modify the table's background color # to be "lightcyan" tab_3 <- 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_4 <- tab_1 %>% tab_options( footnote.sep = " ", footnote.marks = letters ) # Change the padding of data rows to 5px tab_5 <- tab_1 %>% tab_options( row.padding = px(5) ) # Reduce the size of the title and the # subtitle text tab_6 <- tab_1 %>% tab_options( heading.title.font.size = "small", heading.subtitle.font.size = "small" )