0

This is a follow up in my previous question, Why can't I center a group?

I asked why I can't use \centering to center a group. I got an answer saying that a paragraph is processed when a \par (or a blank line) is found. And only if I leave a blank line / the \par command BEFORE closing the group it will process the \centering command.

Alright that worked. BUT, following that explanation I was thinking if I do something like

\centering this is a text

this is another text

or

\centering this is a text \par this is another text

"this is another text" should not be centered, as the paragraph "this is a text" ends with the empty line / the \par.

What am I getting wrong?

Thanks

  • 1
    the \par does not extinguish the effet of \centering, which mainly sets \leftskip and \rightskip to infinitely stretchable glue so that text is centered. – user4686 Sep 20 '18 at 20:25
  • Alright, but why does the same thing not happen when I put the hole thing in a group? I mean that outs me back to my previous question, or more specifically why does the \centering not take place without the \par in a group? – Anton Neundorfer Sep 20 '18 at 20:36
  • During paragraph "parsing" TeX accumulates "horizontal" material (characters, glues, penalties, ...) until it encounters \par (or a blank line which creates a \par token not written by user). Only then does it apply its algorithms to split the "horizontal" material into a paragraph composed of lines. – user4686 Sep 20 '18 at 21:15
3

\centering is a declaration and therefore its scope extends “forever”, but “forever” means “until the group where the declaration is issued ends”.

In your case \centering is issued at the top level, so its scope extends up to the end of the document, unless countermanded by a similar declaration such as \raggedright or \raggedleft. There is no \uncentering declaration, so grouping is necessary.

However, by rule of TeX, a paragraph is set with the values of some relevant parameters active at the point \par is executed.

Thus, as in your previous question,

{\centering This text will not be centered}

And neither this one

will typeset two normally justified paragraphs, because the \par implied by the blank line acts when the scope of \centering has ended, restoring the paragraphing parameters to the values they had before the {.

If you want centered text followed by justified text, you need to do two paragraphs:

{\centering This text will be centered\par}
\noindent And this text will start from the left margin.

However, good typography dictates that the centered part is separated by the justified one:

\begin{center}
This text will be centered
\end{center}
And this text will start from the left margin.

Examples

\documentclass{article}

\begin{document}

\section{Bad}

{\centering This text will not be centered}

And neither this one

\section{Ugly}

{\centering This text will be centered\par}
\noindent And this text will start from the left margin.

\section{Good}

\begin{center}
This text will be centered
\end{center}
And this text will start from the left margin.

\end{document}

enter image description here

| improve this answer | |
1

And only if I leave a blank line / the \par command BEFORE closing the group it will process the \centering command.

This is misleading. The \centering has an immediate effect on some parameters. However, only the values of those parameters in place at the time the paragraph builder is triggered by a \par (either explicit or implicit from a blank line) will influence the paragraph shape.

So the \centering command is "processed" immediately but may have nil effect if a group closes before the next \par or another command again resets the paragraph parameters (leftskip, rightskip mainly).

Notice that the same applies to the \baselineskip for example.

Perhaps, don't use LaTeX2e "command" terminology which is misleading. TeX is a macro-expansion language and \centering is a macro.

$ latexdef centering

\centering:
macro:->\let \\\@centercr \rightskip \@flushglue \leftskip \@flushglue \parindent \z@ \parfillskip \z@skip

As we see in the above it does some assignments. These assignments are canceled if a group closes. If that happens before the \par, the effet on the paragraph builder will be nil.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.