Skip to content

Align

IAlign wraps a single child and positions it left / centre / right within the available width. Useful for centring a panel, justifying a markup label, or forcing a child to sit on the right edge.

When to use

  • Centring a fixed-width widget (logo, panel, calendar) in the middle of the terminal.
  • Right-aligning a status line or footer.

For per-line text alignment, Markup and Paragraph carry their own WithAlignment setters; reach for Align only when you want to position a whole widget horizontally.

Basic usage

pascal
AnsiConsole.Write(
  Widgets.Align(Widgets.Markup('[bold]centered[/]'), TAlignment.Center));

AnsiConsole.Write(
  Widgets.Align(Widgets.Markup('[italic]right[/]'), TAlignment.Right));

In a wider container the difference becomes obvious - the left edge of the child moves accordingly.

Configuration

MethodPurpose
WithAlignment(value)Change horizontal alignment — TAlignment.Left / Center / Right.
WithVerticalAlignment(value)Vertical positioning when the parent has slack — TVerticalAlignment.Top / Middle / Bottom.
pascal
AnsiConsole.Write(
  Widgets.Align(panel, TAlignment.Center)
    .WithVerticalAlignment(TVerticalAlignment.Middle));

API reference

See also

  • Padder — when you also want padding around the child.
  • Panel — for a bordered, centered region.
  • Markup / Paragraph — for per-line alignment.

Released under the MIT License.