Hi all,
I noticed that, wenn I'm doing a presentation and put \centering on a slide, after that the text on the other slides is also centered, although I had enclosed the \centering command with {}. For example:
%Slide 1
{\centering Here is the text I want to be centered.}
%Slide 2
And here is the text I don't want to be centered, but it still is.
Why is that?
Thank you very much,
Alexander
General ⇒ Can't stom centering
- Stefan Kottwitz
- Site Admin
- Posts: 10310
- Joined: Mon Mar 10, 2008 9:44 pm
Can't stom centering
Hi Alexander,
try a paragraph break by an empty line or \par (or break the line by \\) to end \centering:
Stefan
try a paragraph break by an empty line or \par (or break the line by \\) to end \centering:
Code: Select all
{\centering Here is the text I want to be centered.\\}
LaTeX.org admin
Re: Can't stom centering
Hello Stephen,
I tried that but it didn't want to compile the file. However, this is not a big thing, as I just use \begin{center}. I was just wondering why the hell it does that. Thank you for your advice.
I tried that but it didn't want to compile the file. However, this is not a big thing, as I just use \begin{center}. I was just wondering why the hell it does that. Thank you for your advice.
- Stefan Kottwitz
- Site Admin
- Posts: 10310
- Joined: Mon Mar 10, 2008 9:44 pm
Can't stom centering
See here: \centering.
The scope of \centering needs to be limited, for instance by \par, else it affects the next lines too.
\begin{center} uses \centering internally too, but puts a list around it. One side effect of \begin{center} is that additional vertical space occures before and after the centered Text. If I don't want that I use {\centering text \\} or similar with \par.
Stefan
The scope of \centering needs to be limited, for instance by \par, else it affects the next lines too.
\begin{center} uses \centering internally too, but puts a list around it. One side effect of \begin{center} is that additional vertical space occures before and after the centered Text. If I don't want that I use {\centering text \\} or similar with \par.
Stefan
LaTeX.org admin
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Can't stom centering
To avoid that, you could define a new environment (best placed in the preamble) that has no additional space above and below the centred text. Corresponding to its purpose I called the new environment centered.Stefan_K wrote:[...] One side effect of \begin{center} is that additional vertical space occures before and after the centered Text. [...]
Code: Select all
Code, edit and compile here:
\newenvironment{centered}{%\begin{list}{}{%\topsep0pt}\centering\item[]}{\end{list}}
Best regards
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Can't stom centering
Thank you both for the valuable information. It really helped.