gt (version 0.2.2)

cols_align: Set the alignment of columns

Description

The individual alignments of columns (which includes the column labels and all of their data cells) can be modified. We have the option to align text to the left, the center, and the right. In a less explicit manner, we can allow gt to automatically choose the alignment of each column based on the data type (with the auto option).

Usage

cols_align(data, align = c("auto", "left", "center", "right"), columns = TRUE)

Arguments

data

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

align

The alignment type. This can be any of "center", "left", or "right" for center-, left-, or center-alignment. Alternatively, the "auto" option (the default), will automatically align values in columns according to the data type (see the Details section for specifics on which alignments are applied).

columns

An optional vector of column names for which the alignment should be applied. If nothing is supplied, or if columns is TRUE, then the chosen alignment affects all columns.

Value

An object of class gt_tbl.

Figures

Function ID

4-1

Details

When you create a gt table object using gt(), automatic alignment of column labels and their data cells is performed. By default, left-alignment is applied to columns of class character, Date, or POSIXct; center-alignment is for columns of class logical, factor, or list; and right-alignment is used for the numeric and integer columns.

See Also

Other Modify Columns: cols_hide(), cols_label(), cols_merge_range(), cols_merge_uncert(), cols_merge(), cols_move_to_end(), cols_move_to_start(), cols_move(), cols_width()

Examples

Run this code
# NOT RUN {
# Use `countrypops` to create a gt table;
# align the `population` column data to
# the left
tab_1 <-
  countrypops %>%
  dplyr::select(-contains("code")) %>%
  dplyr::filter(country_name == "Mongolia") %>%
  tail(5) %>%
  gt() %>%
  cols_align(
    align = "left",
    columns = vars(population)
  )

# }

Run the code above in your browser using DataLab