Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Why linebreaks break the line height within certain environments with size-changing macros?

I'm trying to understand what's the difference between these three approaches:

  1. \newenvironment
  2. between {} or \begingroup/\endgroup
  3. inside a minipage

\documentclass{article}
\begin{document}
\thispagestyle{empty}
\section{With newenvironment}

\newenvironment{env}{\begin{center}\LARGE}{\end{center}}
\begin{env}
  Text with\\linebreak
\end{env}

\section{With begin/endgroup}

\begin{center}
{\LARGE
Text with\\linebreak}
\end{center}

\begin{center}
\begingroup
\LARGE
Text with\\linebreak
\endgroup
\end{center}

\section{With minipage}

\begin{center}
\begin{minipage}{\textwidth}\centering
  \LARGE
  Text with\\linebreak
\end{minipage}
\end{center}

\end{document}

enter image description here

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Let's see what happens with the first example:

\begin{center}
{\LARGE
Text with\\linebreak}
\end{center}

You open a group (\begin) and order TeX to center lines; in this environment \\ is just \par with some code added to make it obey the usual syntax with *-variant and optional spacing argument.

Then you open another group with { (with \begingroup it would be the same, as long as the group is ended with \endgroup instead of }) in which you issue the \LARGE command.

The fact that \\ does \par means that two paragraphs are typeset; the first is set with the baselineskip pertaining to \LARGE. But the second (with the word linebreak not: indeed the center environment issues a \par to finish off the environment, but this \par comes along when the group started with { has ended and the font size command has been undone. So the second paragraph is typeset with the baselineskip that is in force when the \end{center} is seen, that is, the value it had when the center environment was started. The lines don't overlap because TeX doesn't normally do it (1pt of vertical space will be between the two lines, more precisely the value of \lineskip).

How to solve the issue? Being simple!

\begin{center}
\LARGE
Text with\\
linebreak
\end{center}

The inner group does nothing good and something bad. The group opened by \begin is closed by \end, so the setting of \LARGE will be undone anyway.

If you do it with your env environment, you just add a grouping, but

\begin{env}
Text with\\
linebreak
\end{env}

will work correctly, because it essentially resolves into

\begingroup
\begin{center}
\LARGE
Text with\\
linebreak
\end{center}
\endgroup

(the outer group is provided by \begin{env} and \end{env}), so what I said above applies.

Adding a minipage is probably not what you want: just look at the output of this example to see why:

\documentclass[twocolumn]{article}
\usepackage{lipsum}
\begin{document}
\lipsum*[2]
\begin{center}
\LARGE
Text with\\
linebreak
\end{center}
\lipsum[2]

\newpage

\lipsum*[2]
\begin{center}
\begin{minipage}{\columnwidth}
\centering
\LARGE
Text with\\
linebreak
\end{minipage}
\end{center}
\lipsum[2]

\end{document}

enter image description here

Why is the spacing different? The minipage in the right column has large height and depth, so above and below the minipage TeX uses the \lineskip glue, while in the left column the stated values of \baselineskip are used.

share|improve this answer
add comment

Technically you're not doing the same with each component. The environment env and minipage all have a scope for \LARGE that is ended by the environment as a \par. It's this paragraph delimiter that sets the entire contents - including the baseline skip - in the appropriate font.

To remedy this in your example, issue a par within the extent of the font formatting command \LARGE:

enter image description here

\documentclass{article}
\begin{document}
\thispagestyle{empty}
\section{With newenvironment}

\newenvironment{env}{\begin{center}\LARGE}{\end{center}}
\begin{env}
  Text with\\linebreak
\end{env}

\section{With begin/endgroup}

\begin{center}
{\LARGE
Text with\\linebreak\par}% <---- Added \par
\end{center}

\begin{center}
\begingroup
\LARGE
Text with\\linebreak\par% <---- Added \par
\endgroup
\end{center}

\section{With minipage}

\begin{center}
\begin{minipage}{\textwidth}\centering
  \LARGE
  Text with\\linebreak
\end{minipage}
\end{center}
share|improve this answer
    
Adding \par? Sorry, no. –  egreg Sep 25 '13 at 9:17
    
@egreg: I don't understand "sorry, no". Surely in the bigger scheme of things the use of \par when working in grouped scope suffices. My assumption from the OP's post was a very particular case and not necessarily localized to an environment that contains only 2 lines of code in a different font. Your approach is merely to suggesting removing the grouping inside the environment. –  Werner Sep 25 '13 at 17:17
    
The right way is to remove the additional grouping. Or using \\, as you're in center. –  egreg Sep 25 '13 at 17:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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