Centering Text

Another common formatting task is centering text. For example, you might want to center the title of a document or individual headings within a document. Emacs provides commands to center lines, paragraphs, and regions.

First make sure you’re in text mode. Look at the mode line and, if the word Text is displayed, you are in text mode. If not, type ESC x text-mode RETURN to enter text mode. Now you can center a line by simply typing the line you want to center (or moving anywhere on an existing line), then pressing ESC s.

Type: Annual Report

Centering Text

Type: ESC s

Centering Text

Emacs centers the line.

You can also center paragraphs and regions. In both cases, Emacs does line-by-line centering rather than block centering. To center a paragraph, use the command ESC S (for center-paragraph); to center a region, use ESC x center-region. For example, let’s say you want to center the following quotation.

Initial state:

Centering Text

Type: ESC S

Centering Text

Text is now centered.

In this case, line-by-line centering looks rather artistic. But there are times when you might wish Emacs did block centering. You can replicate this ...

Get Learning GNU Emacs, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.