# How to reduce the vertical gap between two align environments?

I have four formulas divided into two groups that need to be typeset. The first three are aligned at the equal sign. The fourth needs to be aligned in some places alone, and the alignment is also written in the code. So what can be done to reduce the gap between the two environments? This problem has been bugging me for a while, as my fourth formula is long and a bit fiddly to deal with.

\begin{align}
\rho =&\left| \left( s'-s \right) \sin \theta -a\cos \theta \right|\\
z=&\left( s'-s \right) \cos \theta +a\sin \theta\\
\varphi=&\begin{cases}
0,\left( s'-s \right) \sin \theta -a\cos \theta \geqslant 0\\
\pi ,\left( s'-s \right) \sin \theta -a\cos \theta <0\\\end{cases}
\end{align}
\begin{align}
K\left( \rho,\varphi,z \right) =&\int_{-\infty}^{\infty}{\exp \left( -i k_z z \right) d k_z}\nonumber\\
&\times \int_0^{\infty}{\left[ \frac{\cos ^2\theta S_1\left( k_z,\lambda \right) +\sin ^2\theta S_4\left( k_z,\lambda ,\varphi  \right)}{B\left( k_z,\lambda \right)}J_0\left( \lambda \rho  \right) \right.}\nonumber\\
&\left. +\frac{2\sin \theta \cos \theta S_2\left( k_z,\lambda ,\varphi  \right) +\sin ^2\theta S_5\left( k_z,\lambda ,\varphi  \right)}{B\left( k_z,\lambda \right)}J_1\left( \lambda \rho  \right) \right] \lambda d\lambda
\end{align}


• Why is this not a single align instead? Unrelated: that \left[ ... \right. ... \left. ... \right] construction is fragile, it might not give the same size []'s, better to manually scale via, say, \Bigl[ ... \Bigr] then there is also no need for the \right/left . Mar 22, 2022 at 12:45
• BTW 2: when aligning on the right of a relation remember to use  = {} & not =& otherwise the spacing in the = is wrong Mar 22, 2022 at 12:46

As a rule you should never use two display math environments in a row, otherwise you get bad vertical spacing, as you observed. I guess you don't want a single align because the last formula has no reason to be aligned with the previous ones. In this case you could nest your two align environments in an outer gather environment (this is the chief exception to the general rule "do not nest display math environments"). I propose a slightly different version based on nested aligned:

\documentclass{article}
\usepackage{geometry} % more generous margins
\usepackage{mathtools,amssymb}
\DeclarePairedDelimiter{\abs}{|}{|}

\begin{document}

\begin{gather}
\begin{align}
\rho &= \abs{\left( s'-s \right) \sin \theta -a\cos \theta }\\
z &= (s'-s) \cos \theta + a \sin\theta\\
\varphi &=
\begin{cases}
0,  & (s'-s) \sin\theta -a \cos\theta \geqslant 0\\
\pi, & (s'-s) \sin\theta -a \cos\theta <0
\end{cases}
\end{align}\\
\begin{aligned}[b]
K(\rho,\varphi,z) ={}& \int_{-\infty}^{\infty} \exp( -i k_z z ) d k_z \\
&
\begin{aligned}[b]
\times \int_0^{\infty} \biggl[ & \frac{\cos^2\theta S_1(k_z,\lambda) +\sin^2\theta S_4(k_z,\lambda ,\varphi)}{B( k_z,\lambda)}J_0(\lambda\rho)\\
&+\frac{2\sin \theta \cos \theta S_2(k_z,\lambda ,\varphi ) +\sin ^2\theta S_5(k_z,\lambda,\varphi )}{B(k_z,\lambda)}J_1(\lambda \rho ) \biggr] \lambda d\lambda
\end{aligned}
\end{aligned}
\end{gather}

\end{document}


Personally I think a sentence would be appropriate between the two blocks, but that's a matter of taste.

• Using =& leads to inconsistent spacing. If you need the alignment point to be after the equal then use ={}&.
• I removed all \left/\right pairs. Most of them were doing nothing but damage: compare $S_1\left( k_z,\lambda \right)$ vs $S_1( k_z,\lambda)$ .
• Splitting \left[blabla\right. and \left.blabla\right] between lines is a risky bet: nobody guarantees you that the brackets will have the same size. Prefer manual sizes in general, and surely across different lines.

mathtools.sty has an opton \SwapAboveDisplaySkip

\begin{align}
\rho =&\left| \left( s'-s \right) \sin \theta -a\cos \theta \right|\\
z=&\left( s'-s \right) \cos \theta +a\sin \theta\\
\varphi=&\begin{cases}
0,\left( s'-s \right) \sin \theta -a\cos \theta \geqslant 0\\
\pi ,\left( s'-s \right) \sin \theta -a\cos \theta <0\\\end{cases}
\end{align}
\begin{align}
\SwapAboveDisplaySkip
K\left( \rho,\varphi,z \right) =&\int_{-\infty}^{\infty}{\exp \left( -i k_z z \right) d k_z}\nonumber\\
&\times \int_0^{\infty}{\left[ \frac{\cos ^2\theta S_1\left( k_z,\lambda \right) +\sin ^2\theta S_4\left( k_z,\lambda ,\varphi  \right)}{B\left( k_z,\lambda \right)}J_0\left( \lambda \rho  \right) \right.}\nonumber\\
&\left. +\frac{2\sin \theta \cos \theta S_2\left( k_z,\lambda ,\varphi  \right) +\sin ^2\theta S_5\left( k_z,\lambda ,\varphi  \right)}{B\left( k_z,\lambda \right)}J_1\left( \lambda \rho  \right) \right] \lambda d\lambda
\end{align}


This doesn't exactly answer the question, but my suggestion (as others have mentioned) is to avoid consecutive align environments. From an editing perspective, the equations should read as parts of sentences, so I would add a comma at the end of the first align, followed by a short phrase to connect the sentence to the second align, which then ends with a period.

Other minor changes: &= instead of =& in the first align, ={}& instead of =& in the second align.

\documentclass{article}
\usepackage{mathtools,amssymb}

\begin{document}
\noindent ..., so if we set
\begin{align}
\rho &=\left| \left( s'-s \right) \sin \theta -a\cos \theta \right|\\
z&=\left( s'-s \right) \cos \theta +a\sin \theta\\
\varphi&=\begin{cases}
0,\left( s'-s \right) \sin \theta -a\cos \theta \geqslant 0\\
\pi ,\left( s'-s \right) \sin \theta -a\cos \theta <0,\\\end{cases}
\end{align}
it then follows that
\begin{align}
K\left( \rho,\varphi,z \right) ={}&\int_{-\infty}^{\infty}{\exp \left( -i k_z z \right) d k_z}\nonumber\\
&\times \int_0^{\infty}{\left[ \frac{\cos ^2\theta S_1\left( k_z,\lambda \right) +\sin ^2\theta S_4\left( k_z,\lambda ,\varphi  \right)}{B\left( k_z,\lambda \right)}J_0\left( \lambda \rho  \right) \right.}\nonumber\\
&\left. +\frac{2\sin \theta \cos \theta S_2\left( k_z,\lambda ,\varphi  \right) +\sin ^2\theta S_5\left( k_z,\lambda ,\varphi  \right)}{B\left( k_z,\lambda \right)}J_1\left( \lambda \rho  \right) \right] \lambda d\lambda.
\end{align}
\end{document}