# How to get rid of extra space before align and gather envronments, but allow page breaks?

I am editing a rather long text which contains many equations and floats, and encountered a problem with the align and gather environments.

MWE:

\documentclass[preview]{standalone}
\usepackage{amsmath}
\begin{document}

Paragraph one. Lorem ipsum dolor sit amet, consecuteur adipiscing elit.

\begin{gather*}
\boxed{\sum_{x=1}^{N} A_x} \\
\boxed{\sum_{x=1}^{N} A_x}
\end{gather*}

Paragraph two. Lorem ipsum dolor sit amet, consecuteur adipiscing elit.

\end{document}


Result:

There is too much vertical space between the first paragraph and the equation, as if an extra empty paragraph was inserted. If I delete the blank line between the first paragraph and the math environment, there is no extra space, but the page can't be broken at that point and I often I end up with orphans. The extra space is not present when I use the equation environment or :

\documentclass[preview]{standalone}
\usepackage{amsmath}
\begin{document}

Paragraph one. Lorem ipsum dolor sit amet, consecuteur adipiscing elit.

$\boxed{\sum_{x=1}^{N} A_x}$
$\boxed{\sum_{x=1}^{N} A_x}$

Paragraph two. Lorem ipsum dolor sit amet, consecuteur adipiscing elit.

\end{document}


Result:

How can I get rid of the unwanted vertical space, but at the same time allow page breaks before the environment?

• Pages should never start with a displayed equation, if it's not a continuation of a display from the previous page. You can allow breaks inside alignment displays by issuing \allowdisplaybreaks in the document preamble, but never leave a blank line before a display. – egreg Jul 13 '13 at 20:16
• Why not? If I use \allowdisplaybreaks, then pages can start with fragments of equations. Why not also allow them to start with complete equations too? – Krzysztof Kosiński Jul 14 '13 at 0:28
• @KrzysztofKosiński -- the "edict" against starting a page with a displayed equation is based on long tradition. this is mentioned in the texbook on p.189 in the last (double-danger-sign) paragraph. – barbara beeton Aug 27 '13 at 12:57

Pages should never start with a displayed equation that is not a continuation of a display from the previous page (and this case should be a kind of last resort).

You can automatically allow page breaks inside multiline alignment displays by issuing

\allowdisplaybreaks


(an amsmath command) in the document preamble, but TeX will never break a page before a display, unless you play some dirty trick yourself.

Never leave a blank line before a display.

I found a solution, and no real justification for the ban on page breaks before a displayed equation was given, so I'm leaving a note to others who might see the question.

To allow a break before a specific displayed equation, but get rid of the extra vertical space, put \pagebreak[0] in place of the first blank line:

\documentclass[preview]{standalone}
\usepackage{amsmath}
\begin{document}

Paragraph one. Lorem ipsum dolor sit amet, consecuteur adipiscing elit.
\pagebreak[0]
\begin{gather*}
\boxed{\sum_{x=1}^{N} A_x} \\
\boxed{\sum_{x=1}^{N} A_x}
\end{gather*}

Paragraph two. Lorem ipsum dolor sit amet, consecuteur adipiscing elit.

\end{document}


To allow breaks everywhere, redefine \predisplaypenalty in the preamble:

\makeatletter
\predisplaypenalty=\@medpenalty
\makeatother


Both of these ways allow the page breaks to happen.