# Where does the space before \align* come from?

In the following MWE, what is responsible for the large space before the align environment? How can I remove it (it doesn't appear if I change to $ $ and remove amsmath) ?

\documentclass{article}

\usepackage[english]{babel}
\usepackage{amsmath,amssymb}
\usepackage{lipsum}

\begin{document}
\setlength{\parskip}{0pt}
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}

\lipsum*[2]

\lipsum*[2]

\begin{align*}1, 2, 3\end{align*}

\lipsum*[2]

\lipsum*[2]
\end{document}


I have read Spacing around align environments (but it doesn't cover the case in which there's a \par before \align and Remove vertical space around align (but it attributes the space to \parskip, which seems wrong: setting \parskip to 0 pt doesn't remove the space). I also read Remove extra vertical space in amsmath's align environment and Remove vertical space around align equations, but they just say that one shouldn't leave a \par before an \align. I'm curious to know what actually causes this blank space, even with all seemingly relevant lengths set to zero.

# Edit for Reopen

Why does LaTeX insert space before formulas? is related, but it doesn't address the why: it says that leaving a blank line in the source causes the space but it doesn't say who is adding this space (and it's clearly an amsmath-specific this: the regular displaymath doesn't do that).

• The space you're looking for is \parskip + \baselineskip. – Werner Nov 2 '16 at 5:54
• Ah, of course! But why is it adding a \baselineskip in there? – Clément Nov 2 '16 at 6:02
• It isn't a space it's a spurious line of a paragraph. – David Carlisle Nov 2 '16 at 7:34
• @Clément you could ask that the answer there is extended but the question is an almost exact dupe "why insert space before" and "where does the space before" couldn't be much closer. – David Carlisle Nov 2 '16 at 16:31
• @Clément maybe I'll add some text somewhere:-) – David Carlisle Nov 2 '16 at 22:10

## 2 Answers

You ask,

Where does the [vertical] space before \align* come from?

It comes from an input mistake -- not a syntax error, mind you, but a mistake nevertheless -- in your code: Display-math environments should never, ever occur at the start of a paragraph.

In the following code, which preserves your \setlength instructions, the instance of align* that is not preceded by a paragraph break features no extra vertical whitespace; in contrast, the instance of align* that is preceded by a paragraph break does feature the dreaded extra whitespace. Observe that this happens even though the five length parameters have been set to 0pt.

To recap: Never begin a paragraph with a display-math environment. Not only is it poor practice from a typographic standpoint, it's also poor practice from a discursive/explanatory standpoint.

\documentclass{article}
\usepackage{amsmath,lipsum}

\begin{document}
\setlength{\parskip}{0pt}
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}
\lipsum*[2]
\begin{align*}1, 2, 3\end{align*} % no paragraph break before  this 'align*'
\lipsum*[2]

\begin{align*}1, 2, 3\end{align*} % paragraph break before this 'align*'
\lipsum*[2]
\end{document}

• Hmm. Aren't the various lengths in your example reset to their original values by the \normalsize issued when entering \begin{document}? – Clément Nov 2 '16 at 6:17
• @Clément - I'd issue a warning, not an error message. :-) No rules without exceptions, right? I can't think of an exception to the rule that one shouldn't start a paragraph with displayed math. However, you (or others) just might, in which case it wouldn't be good to be stopped by an outright error message... – Mico Nov 2 '16 at 7:04
• @DavidCarlisle - If you take my MWE, don't load amsmath, and replace the instances of \begin{align*} with  and the instances of \end{align*} with , you will not get the extra vertical space if the displayed equation occurs at the start of the paragraph. This must be because of the \ifvmode\nointerlineskip portion of the code for \[. However, as you've pointed out, the extra vertical space does occur if  or is used to initiate a displayed equation. – Mico Nov 2 '16 at 9:10
• @Mico with \[ the nointerlineskip reduced the damage a bit but there is still a spurious hbox there it's just harder to spot:-) Note the main way this "space" differs from a vertical space is that as it is an hbox it is not discarded at a page break. – David Carlisle Nov 2 '16 at 9:14
• I honestly think that this is a perfect example of how truly awful latex is. The worst bit is that there's no sensible fix to globally allow a line break before these blocks. The whitespace-sensitive-but-still-a-total-eyesore thing is hilarious too. – N. McA. May 19 '18 at 21:33

Not sure of the actual reason but I manage to fix that by placing a \vspace{0.2em}

\begin{document}
\setlength{\parskip}{0pt}
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}

\lipsum*[2]

\lipsum*[2]
\vspace{0.2em}
\begin{align*}1, 2, 3\end{align*}

\lipsum*[2]

\lipsum*[2]

\end{document}

• Your \vspace just removes the implicit \par, no? – Clément Nov 2 '16 at 5:00
• I believe so.. maybe my solution isn't a good one.. – shahrina ismail Nov 2 '16 at 5:32
• sorry this is not the correct fix at all. – David Carlisle Nov 2 '16 at 7:35
• irrespective of whether using \vspace is a good idea, the units used are not. em is a horizontal unit; ex or \baselineskip is a vertical unit. they shouldn't be mixed up. – barbara beeton Nov 2 '16 at 18:38