Skip to contents

Indentation of row labels is an effective way for establishing structure in a table stub. The tab_stub_indent() function allows for fine control over row label indentation in the stub. We can use an explicit definition of an indentation level, or, employ an indentation directive using keywords.


tab_stub_indent(data, rows, indent = "increase")



The gt table data object

obj:<gt_tbl> // required

This is the gt table object that is commonly created through use of the gt() function.


Rows to target

<row-targeting expression> // required

The rows to consider for the indentation change. The default everything() results in all rows being targeted. Alternatively, we can supply a vector of row captions within c(), a vector of row indices, or a select helper function. Examples of select helper functions include starts_with(), ends_with(), contains(), matches(), one_of(), num_range(), and everything(). We can also use expressions to filter down to the rows we need (e.g., [colname_1] > 100 & [colname_2] < 50).


Indentation directive

scalar<character|numeric|integer> // default: "increase"

An indentation directive either as a keyword describing the indentation change or as an explicit integer value for directly setting the indentation level. The keyword "increase" (the default) will increase the indentation level by one; "decrease" will do the same in the reverse direction. The starting indentation level of 0 means no indentation and this values serves as a lower bound. The upper bound for indentation is at level 5.


An object of class gt_tbl.

Compatibility of arguments with the from_column() helper function

The from_column() helper function can be used with the indent argument of tab_stub_indent() to obtain varying parameter values from a specified column within the table. This means that each row label could be indented a little bit differently.

Please note that for this argument (indent), a from_column() call needs to reference a column that has data of the numeric or integer type. Additional columns for parameter values can be generated with the cols_add() function (if not already present). Columns that contain parameter data can also be hidden from final display with cols_hide().


Let's use a summarized version of the pizzaplace dataset to create a gt table with row groups and row labels. With the summary_rows() function, we'll generate summary rows at the top of each row group. With tab_stub_indent() we can add indentation to the row labels in the stub.

pizzaplace |>
  dplyr::group_by(type, size) |>
    sold = dplyr::n(),
    income = sum(price),
    .groups = "drop"
  ) |>
  gt(rowname_col = "size", groupname_col = "type") |>
  tab_header(title = "Pizzas Sold in 2015") |>
  fmt_integer(columns = sold) |>
  fmt_currency(columns = income) |>
    fns = list(label = "All Sizes", fn = "sum"),
    side = "top",
    fmt = list(
      ~ fmt_integer(., columns = sold),
      ~ fmt_currency(., columns = income)
  ) |>
    summary_row.background.color = "gray95",
    row_group.background.color = "#FFEFDB",
    row_group.as_column = TRUE
  ) |>
    rows = everything(),
    indent = 2

This image of a table was generated from the first code example in the `tab_stub_indent()` help file.

Function ID


Function Introduced

v0.7.0 (Aug 25, 2022)

See also