cell_text: Helper for defining custom text styles for table cells

View source: R/helpers.R

cell_textR Documentation

Helper for defining custom text styles for table cells


This helper function is to be used with the tab_style() function, which itself allows for the setting of custom styles to one or more cells. We can also define several styles within a single call of cell_text() and tab_style() will reliably apply those styles to the targeted element.


  color = NULL,
  font = NULL,
  size = NULL,
  align = NULL,
  v_align = NULL,
  style = NULL,
  weight = NULL,
  stretch = NULL,
  decorate = NULL,
  transform = NULL,
  whitespace = NULL,
  indent = NULL



The text color.


The font or collection of fonts (subsequent font names are) used as fallbacks.


The size of the font. Can be provided as a number that is assumed to represent px values (or could be wrapped in the px()) helper function. We can also use one of the following absolute size keywords: "xx-small", "x-small", "small", "medium", "large", "x-large", or "xx-large".


The text alignment. Can be one of either "center", "left", "right", or "justify".


The vertical alignment of the text in the cell. Options are "middle", "top", or "bottom".


The text style. Can be one of either "normal", "italic", or "oblique".


The weight of the font. 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.


Allows for text to either be condensed or expanded. We can use one of the following text-based keywords to describe the degree of condensation/expansion: "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", "normal", "semi-expanded", "expanded", "extra-expanded", or "ultra-expanded". Alternatively, we can supply percentage values from 0\% to 200\%, inclusive. Negative percentage values are not allowed.


Allows for text decoration effect to be applied. Here, we can use "overline", "line-through", or "underline".


Allows for the transformation of text. Options are "uppercase", "lowercase", or "capitalize".


A white-space preservation option. By default, runs of white-space will be collapsed into single spaces but several options exist to govern how white-space is collapsed and how lines might wrap at soft-wrap opportunities. The keyword options are "normal", "nowrap", "pre", "pre-wrap", "pre-line", and "break-spaces".


The indentation of the text. Can be provided as a number that is assumed to represent px values (or could be wrapped in the px()) helper function. Alternatively, this can be given as a percentage (easily constructed with pct()).


A list object of class cell_styles.


Use exibble to create a gt table. Add styles with tab_style() and the cell_text() helper function.

exibble %>%
  dplyr::select(num, currency) %>%
  gt() %>%
    columns = c(num, currency),
    decimals = 1
  ) %>%
    style = cell_text(weight = "bold"),
    locations = cells_body(
      columns = num,
      rows = num >= 5000
  ) %>%
    style = cell_text(style = "italic"),
    locations = cells_body(
      columns = currency,
      rows = currency < 100

Function ID


See Also

Other Helper Functions: adjust_luminance(), cell_borders(), cell_fill(), cells_body(), cells_column_labels(), cells_column_spanners(), cells_footnotes(), cells_grand_summary(), cells_row_groups(), cells_source_notes(), cells_stub_grand_summary(), cells_stub_summary(), cells_stubhead(), cells_stub(), cells_summary(), cells_title(), currency(), default_fonts(), escape_latex(), google_font(), gt_latex_dependencies(), html(), md(), pct(), px(), random_id()

gt documentation built on May 24, 2022, 5:06 p.m.