Pad and align text to a fixed width — add filler characters so each line reaches a target column count, with a choice of how the text sits inside that block.
Alignment modes:
- Left — text starts at the left, padding added on the right.
"hi" → "hi " (8-wide).
- Right — text ends at the right, padding added on the left.
"hi" → " hi".
- Center — text sits in the middle, padding split between both sides (extra pad goes on the right for odd remainders).
"hi" → " hi ".
- Justify — for multi-line input, full-justify every line except the last: words are spread so the line reaches the target width with spaces distributed between them (newspaper-column look).
Options:
- Target width — the column count each line is padded/aligned to (1–200).
- Pad character — the character used to fill the gap. Defaults to a space; common picks are
-, =, ., or 0.
Good to know:
- Lines already at or past the target width are returned unchanged for left/right/center (you can't shrink text by padding).
- Justify needs at least two words on a line to spread; single-word lines are left-aligned.
- Width is measured in characters (Unicode code points), so CJK characters each count as one column — pair with a monospace display for visual alignment.