Center Text Strings

Function to center text strings for display on the text console by prepending the necessary number of spaces to each element.

Keywords
manip, character
Usage
centerText(x, width = getOption("width"))
Arguments
x

Character vector containing text strings to be centered.

width

Desired display width. Defaults to the R display width given by getOption("width").

Details

Each element will be centered individually by prepending the necessary number of spaces to center the text in the specified display width assuming a fixed width font.

Value

Vector of character strings.

See Also

strwrap

Aliases
  • centerText
Examples
cat(centerText("One Line Test"), "\n\n")

mText <-c("This", "is an example",
          " of a multiline text    ",
          "with ",
          "          leading",
          " and trailing         ",
          "spaces.")
cat("\n", centerText(mText), "\n", sep="\n")
Documentation reproduced from package gdata, version 2.18.0, License: GPL-2

Community examples

Looks like there are no examples yet.