Text Formattingthe \centering command

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
yoo
Posts: 5
Joined: Sun Nov 08, 2009 2:38 pm

the \centering command

Post by yoo »

Apparently, what I think \centering should do is not really what it does. For example

Code: Select all

\documentclass{article}
\begin{document}

{\centering Why is this line not centered?}

{A

\centering B

C}

a

\centering b

c

% why is it that c is centered yet C is not?

\end{document}
Maybe I should stick to the center environment. But I want to fix my incorrect mental model of the \centering command

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

the \centering command

Post by Stefan Kottwitz »

Hi,

\centering or justifying work per line or paragraph. If you want to ensure that the line is centered then end the line, using \\ or \newline or \par or an empty line for a paragraph break.
The braces limit the effect of \centering, after } the text is not centered any more. The C is still on that line, that's not centered, that's why the C is also left aligned. If you want to center C then end the line before } instead of after it.
The last small c is centered because \centering is still valid, it's scope is not limited by braces.

Stefan
LaTeX.org admin
Post Reply