align {flextable}R Documentation

Set text alignment

Description

change text alignment of selected rows and columns of a flextable.

Usage

align(
  x,
  i = NULL,
  j = NULL,
  align = "left",
  part = c("body", "header", "footer", "all")
)

align_text_col(x, align = "left", header = TRUE, footer = TRUE)

align_nottext_col(x, align = "right", header = TRUE, footer = TRUE)

Arguments

x

a flextable object

i

rows selection

j

columns selection

align

text alignment - a single character value, or a vector of character values equal in length to the number of columns selected by j. Expected values must be from the set of ('left', 'right', 'center', or 'justify').

If the number of columns is a multiple of the length of the align parameter, then the values in align will be recycled across the remaining columns.

part

partname of the table (one of 'body', 'header', 'footer', 'all')

header

should the header be aligned with the body

footer

should the footer be aligned with the body

See Also

Other sugar functions for table style: bg(), bold(), color(), empty_blanks(), font(), fontsize(), highlight(), italic(), keep_with_next(), line_spacing(), padding(), rotate(), tab_settings(), valign()

Examples

# Table of 6 columns
ft_car <- flextable(head(mtcars)[, 2:7])

# All 6 columns right aligned
align(ft_car, align = "right", part = "all")

# Manually specify alignment of each column
align(
  ft_car,
  align = c("left", "right", "left", "center", "center", "right"),
  part = "all")

# Center-align column 2 and left-align column 5
align(ft_car, j = c(2, 5), align = c("center", "left"), part = "all")

# Alternate left and center alignment across columns 1-4 for header only
align(ft_car, j = 1:4, align = c("left", "center"), part = "header")
ftab <- flextable(mtcars)
ftab <- align_text_col(ftab, align = "left")
ftab <- align_nottext_col(ftab, align = "right")
ftab

[Package flextable version 0.9.6 Index]