Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/davidgohel/flextable/llms.txt

Use this file to discover all available pages before exploring further.

align() sets the horizontal alignment of text in selected cells. Two convenience variants — align_text_col() and align_nottext_col() — let you align all text or all non-text columns at once.

Function signatures

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)

Parameters — align()

x
flextable
required
A flextable object.
i
integer | formula | logical
Row selector. Accepts integer indices, a one-sided formula, or a logical vector. NULL selects all rows in the specified part.
j
integer | character | formula
Column selector. Accepts integer indices, column names, or a formula. NULL selects all columns.
align
string | character vector
default:"\"left\""
Text alignment. Accepted values: "left", "right", "center", "justify".You can also pass a character vector with one value per selected column. If the number of columns is a multiple of the vector length, values are recycled.
part
string
default:"\"body\""
Which part of the table to target: "body", "header", "footer", or "all".

Parameters — align_text_col() and align_nottext_col()

x
flextable
required
A flextable object.
align
string
Alignment to apply. Accepted values: "left", "right", "center", "justify".
header
logical
default:"TRUE"
Whether to also apply the alignment to the header part.
Whether to also apply the alignment to the footer part.

Return value

The modified flextable object.

Examples

Right-align all six columns including the header:
ft <- flextable(head(mtcars)[, 2:7])
align(ft, align = "right", part = "all")
Specify a different alignment per column:
ft <- flextable(head(mtcars)[, 2:7])
align(
  ft,
  align = c("left", "right", "left", "center", "center", "right"),
  part = "all"
)
Center column 2 and left-align column 5:
ft <- flextable(head(mtcars)[, 2:7])
align(ft, j = c(2, 5), align = c("center", "left"), part = "all")
Alternate left and center across the first four columns in the header:
ft <- flextable(head(mtcars)[, 2:7])
align(ft, j = 1:4, align = c("left", "center"), part = "header")
Use the convenience functions to align by column type:
ft <- flextable(mtcars)
ft <- align_text_col(ft, align = "left")
ft <- align_nottext_col(ft, align = "right")
ft

See also

  • valign() — set vertical alignment
  • padding() — set cell inner spacing
  • rotate() — rotate cell text
  • style() — apply multiple formatting properties at once

Build docs developers (and LLMs) love