[Tex/LaTex] Mysterious Vertical Space After Theorem Environment Before Align Environment

alignamsthmtheoremsvertical alignment

There are a lot of questions about skip control before and after theorem and align environments, see, please, solution with hack of theorem environment, general solution for align environments, however unexpected mysterious skip has come back.

As a MWE we can use a mixture of MWEs given here and here.

It happens that only white \hrule can slightly improve the situation, however this solution is a little bit ugly.

The question is how not to get unexpected skip in a simple and reasonable way?

Here is a MWE:

MisteriousSkip.tex:

\documentclass[11pt,a4paper]{report}

\usepackage{amsmath,amssymb,amsthm,xpatch}

\setlength{\topsep}{0pt}
\setlength{\partopsep}{0pt plus 0pt minus 0pt}
\setlength{\parskip}{0pt}
\setlength{\parindent}{0pt}

\newtheoremstyle{mytheoremstyle}{0pt}{0pt}{\itshape}{}{\bfseries}{.}{.5em}{} 

\theoremstyle{mytheoremstyle}

\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{lemma}[theorem]{Lemma}

\makeatletter
\xpatchcmd{\proof}{\topsep6\p@\@plus6\p@\relax}{}{}{}
\makeatother

\begin{document}
    \setlength{\abovedisplayskip}{0pt}%
    \setlength{\belowdisplayskip}{0pt}%
    \setlength{\abovedisplayshortskip}{0pt}%
    \setlength{\belowdisplayshortskip}{0pt}%
Some normal text goes here, with a lemma immediately below.
\begin{lemma}
This is the statement of the lemma.
\end{lemma}
%\hrule % if we \hrule, the skip becomes smaller!
\begin{align*}
x_1+x_2+x_3+x_4 &\leq 10 \\
x_5+x_5         &\leq 8 \\
x_7+x_8         &\leq 5 
\end{align*}
\begin{proof}
This is the proof of the lemma, with a mysterious space above.
\end{proof}
Some normal text goes here, with a mysterious space above. \par
The next paragraph comes immediately below.

\end{document}

A screenshot of MysteriousSkip.pdf is below:

enter image description here

Best Answer

Since the align is part of the proof, include it within that environment. Also, it would be advisable to not start a proof with an equation, particularly because of the setup - it sets Proof. by default, necessarily putting the alignment on the following line. Instead, add some informal descriptive text prior to it:

enter image description here

\documentclass{report}

\usepackage{amsmath,amsthm}

\setlength{\parindent}{0pt}

\newtheoremstyle{mytheoremstyle}{0pt}{0pt}{\itshape}{}{\bfseries}{.}{.5em}{} 

\theoremstyle{mytheoremstyle}

\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{lemma}[theorem]{Lemma}

\AtBeginDocument{%
  \setlength{\abovedisplayskip}{0pt}%
  \setlength{\belowdisplayskip}{0pt}%
  \setlength{\abovedisplayshortskip}{0pt}%
  \setlength{\belowdisplayshortskip}{0pt}%
}

\begin{document}
Some normal text goes here, with a lemma immediately below.

\begin{lemma}
This is the statement of the lemma.
\end{lemma}
\begin{proof}
It is possible to derive the following:
\begin{align*}
  x_1 + x_2 + x_3 + x_4                        &\leq 10 \\
                         x_5 + x_6             &\leq 8 \\
                                    x_7 + x_8  &\leq 5 
\end{align*}
This is the proof of the lemma, with a mysterious space above.
\end{proof}

Some normal text goes here, with a mysterious space above.

The next paragraph comes immediately below.

\end{document}