num_pad: Pads text on the left or right so that the width is the same...

View source: R/formatting.R

num_padR Documentation

Pads text on the left or right so that the width is the same for each element of the vector

Description

num_pad() adds spaces to the left or right of each element of a text vector so that all elements have the same width, counted in characters or measured in a font. align_chr() uses it to line up numbers.

Usage

num_pad(
  x,
  pad_left = TRUE,
  padding_character = " ",
  NA_value = "",
  font_family = NULL
)

Arguments

x

vector of text

pad_left

if TRUE (default), pads on the left, otherwise pads on the right

padding_character

character to use for padding, default is ⁠ ⁠ (figure space)

NA_value

value to replace NA

font_family

font in which to measure text widths. If NULL (default) or NA, or if the font is not installed, widths are counted in characters.

Details

By default, text is padded with one padding_character per missing visible character. Markdown markup (e.g., ⁠**⁠, *, ^, ~, and backslash escapes) is not counted. If font_family names an installed font, text is instead padded to equal rendered width in that font, using a combination of figure, punctuation, thin, and hair spaces (padding_character is then ignored). Superscripts and subscripts are measured at 2/3 of the font size.

Value

character vector

Examples

num_pad(c("a", "bb"))
# A minus sign (U+2212) and a figure-space-padded 1 have the same width
num_pad(c("\u22121", "1"), font_family = "Times New Roman")

apa7 documentation built on Dec. 1, 2026, 5:06 p.m.