5

The 'align' environment is awesome and I think it can almost replace the default 'equation' and 'eqnarray' environments. However, I find the vertical spacing of the align equations a little troubling to me.

I observe that if the equation follows a long text line, 'align' and 'equation' do the same spacing; however, if the equation is after a short text line, 'equation' does some compression while 'align' doesn't, so the former results in a better-looking equation.

Here is an example. Is there anyway for 'align' to adjust the spacing the same as 'equation'?

\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage{amsmath}
\begin{document}
\setlength\parindent{0pt}
Using \textit{equation}:
\begin{equation}
x = 1
\end{equation}
Spacing is OK.

\smallskip
(Using \textit{align}):
\begin{align}
x = 1
\end{align}
Spacing is too much.

\bigskip
\textbf{Another Example}

Using \textit{equation}: (long text long text long text)
\begin{equation}
x = 1
\end{equation}
Spacing is OK. (long text long text long text long text)

\smallskip
Using \textit{align}: (long text long text long text long text) 
\begin{align}
x = 1
\end{align}
Spacing is the same. (long text long text long text long text)

\end{document}

enter image description here

  • Welcome to TeX.SX! You can set the lengths \abovedisplayskip and \belowdisplayskip to your liking. – TeXnician Jun 15 '17 at 19:51
  • The issue is that align isn't respecting the \abovedisplayshortskip/\belowdisplayshortskip. I don't recall if there's a solution to this. – TH. Jun 15 '17 at 20:34
  • The answer to this question can be found in subsection 3.1.5 (p. 8) of the manual of the mathtools package (type texdoc mathtool at a terminal emulator prompt to bring it up). – GuM Jun 15 '17 at 22:00
4

The SwapAboveDisplaySkipcommand from mathtools (mentioned by @Gustavo Mezzetti in his comment) doesn't work with multline, nor equation.

The \useshortskip from nccmath (to be used just before the environment, contrary to the mathtools solution, which has to be used at the beginning of the environment) works:

\documentclass[12pt]{article}
\usepackage[english]{babel}
\usepackage{mathtools, nccmath}

\begin{document}

\setlength\parindent{0pt}
Using \textit{equation}:
\begin{equation}
x = 1
\end{equation}
Spacing is OK.

\smallskip
(Using \textit{align}):\useshortskip
\begin{align}
x = 1
\end{align}
Spacing is OK.

\bigskip
(Using \textit{multline}):\useshortskip
\begin{multline}
x =a + b + c + d\\ + f +e +g + h
\end{multline}
Spacing is OK.

\end{document} 

enter image description here

  • Thanks for providing this solution. It works perfectly. Also your comments are very educating to me. – Jiexing Wu Jun 16 '17 at 16:11
2

In the end, I’ve decided to expand my comment to an anwer.

Many of the environments that the amsmath package defines for displaying math do not exploit the “display short skip” mechanism that TeX implements at “machine-level”; this is because, from a TeXnical point of view, those environments do not typeset a “displayed equation”, but rather something more similar to a list environment. Anyway, the mathtoos package provide a partial workaround for this: if the very first thing inside a display environment is the command \SwapAboveDisplaySkip, then the display will be precede by the \abovedisplayshortskip space, and not by \abovedisplayskip. This solution is only partial because it is not automatic: a \SwapAboveDisplaySkip command must be manually inserted wherever it is needed. Finally, it should be remarked that \SwapAboveDisplaySkip cannot be used with the equation and multline environments—but neither it needs to!

Here’s a complete, compilable example:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{mathtools} % also loads "amsmath"



\begin{document}

\setlength\parindent{0pt}

Using \texttt{equation}:
\begin{equation}
    x = 1
\end{equation}
Spacing is OK.

\medskip
Using \texttt{align}:
\begin{align}
    x = 1
\end{align}
Spacing is too much.

\medskip
Using \verb|\SwapAbove...|:
\begin{align}
    \SwapAboveDisplaySkip
    x = 1
\end{align}
Now the spacing is correct.

\bigskip
\textbf{Another Example}

Using \texttt{equation} (long text long text long text):
\begin{equation}
    x = 1
\end{equation}
Spacing is OK.

\smallskip
Using \texttt{align} (long text long text long text long text): 
\begin{align}
    x = 1
\end{align}
Spacing is the same.

\bigskip
\textbf{But Beware:}

Using \verb|\SwapAboveDisplaySkip| (long text long text long text long text):
\begin{align}
    \SwapAboveDisplaySkip
    x = 1
\end{align}
Now the spacing is wrong again (too little)!

\end{document}

The following is the output I get:

Output of the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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