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

Code, edit and compile here:
\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}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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.

Stefan Kottwitz
Site Admin
Posts: 10345
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