73

How could I go about setting the 'above' and 'below' vspaces around the equation environment?

If the same could be done for the subequations or gather environments, this would be a bonus.

3
  • 4
    from your mention of subequations and gather it appears that you are using amsmath. (a mwe would make this more clear.) it is a known bug that, for multi-line equations, \abovedisplayskip is always used instead of \abovedisplayshortskip since multi-line displays are always implemented as a full-width environment. this is scheduled for review and (hoped-for) correction in the next overhaul of amsmath; unfortunately, the overhaul has not yet been firmly scheduled. Sep 1, 2012 at 13:28
  • possible duplicate of Different spacing around equation and align Sep 1, 2012 at 14:08
  • 2
    @MarcoDaniel The suggested duplicate is specifically about making spacing of equation and alignment equal. I think in general it's good to close the more specific question as a duplicates to the general one. The order of appearance on TeX.SX doesn't matter at long sight. Or edit the other question to make it canonical. Perhaps you would find another question where the answer doesn't just mention those lengths, but explain it how to adjust it in the preamble globally, overcoming the reset in \normalsize?
    – Stefan Kottwitz
    Sep 1, 2012 at 17:36

2 Answers 2

63

You can adjust the values of \abovedisplayskip, \belowdisplayskip, \abovedisplayshortskip, \belowdisplayshortskip. The shortskip versions are used in the situation where a short text line comes before the displayed equation: if the text ends before the displayed equation starts, it's good to add less vertical space.

Since document classes often define those skips in \normalsize you could redefine this macro, patch it, or simply add to it, because just setting the values in the preamble would not work then.

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\g@addto@macro\normalsize{%
  \setlength\abovedisplayskip{40pt}
  \setlength\belowdisplayskip{40pt}
  \setlength\abovedisplayshortskip{40pt}
  \setlength\belowdisplayshortskip{40pt}
}
\makeatother
\begin{document}
text
\begin{gather}
  1 + 1 = 2
\end{gather}
text
\begin{equation}
  1 + 1 = 2
\end{equation}
\end{document}

The same can be done without \g@addto@macro, so without any @ and not requiring \makeatletter and \makeatother, by using \expandafter:

\expandafter\def\expandafter\normalsize\expandafter{%
    \normalsize
    \setlength\abovedisplayskip{40pt}
    \setlength\belowdisplayskip{40pt}
    \setlength\abovedisplayshortskip{40pt}
    \setlength\belowdisplayshortskip{40pt}
}

I prefer the way of adding to \normalsize, because both redefining and patching require knowing the exact definition of \normalsize used by the document class. Bot ways I described earlier in the LaTeX Community forum, in an answer to Can't set vertical whitespace in the preamble.

More information is available in the excellent mathmode documentation.

7
  • @lockstep Added. Btw. I used the opportunity to explain the \normalsize way, because I did not see that one here yet, just adjusting the values and perhaps adding that it should be used after \begin{document}, which isn't the best, such as here.
    – Stefan Kottwitz
    Sep 1, 2012 at 12:09
  • @StefanKottwitz -- even with the \expandafters, wouldn't it be "safer" to save the prior value of \normalsize, say \let\originalnormalsize\normalsize, and use that in the definition, rather than \normalsize itself? Sep 1, 2012 at 12:41
  • @barbarabeeton The \let way is indeed a nice and more understandable way. However regarding being safe, it adds the risk that the additional macro used for saving is already used by a class or package. Not a big deal, just to add it. That's why I tend to use \newcommand*{\origmacro}{} before saving, so at least an error would be raised instead of silently overwriting.
    – Stefan Kottwitz
    Sep 1, 2012 at 12:50
  • 2
    Should’t there be %’s at the line end to prevent spurious spaces?!
    – Tobi
    Sep 24, 2014 at 15:30
  • 1
    @Mankka Thank you, I updated the link!
    – Stefan Kottwitz
    Apr 3 at 15:12
20

As an update of Stefan's answer.

Your questions should be closed as duplicated You will find a lot of question/answeres here. E.g.:

Different spacing around equation and align

Before showing some other approaches here a very important fact:

Don't miss the glue! The length \abovedisplayskip etc. can be defined with a glue and so you allow LaTeX to setup the space more flexible. Please read this question/answer: What is glue stretching?

However I want to show an other possibility to setup the length. First of all you can use the command \AtBeginDocument. The font will be setup at the beginning of the document and so the hook will executed the stuff later:

\AtBeginDocument{%
 \abovedisplayskip=12pt plus 3pt minus 9pt
 \abovedisplayshortskip=0pt plus 3pt
 \belowdisplayskip=12pt plus 3pt minus 9pt
 \belowdisplayshortskip=7pt plus 3pt minus 4pt
}

The command \g@addto@macro is an internal macro. Packages like etoolbox or the newer one xpatch are providing more robust versions of the command \g@addto@macro. Show instead of using the internal command and without special handling of the @ you can use:

\usepackage{etoolbox}
\apptocmd\normalsize{%
 \abovedisplayskip=12pt plus 3pt minus 9pt
 \abovedisplayshortskip=0pt plus 3pt
 \belowdisplayskip=12pt plus 3pt minus 9pt
 \belowdisplayshortskip=7pt plus 3pt minus 4pt
}{}{}

or

\usepackage{xpatch}
\xapptocmd\normalsize{%
 \abovedisplayskip=12pt plus 3pt minus 9pt
 \abovedisplayshortskip=0pt plus 3pt
 \belowdisplayskip=12pt plus 3pt minus 9pt
 \belowdisplayshortskip=7pt plus 3pt minus 4pt
}{}{}

That is work with gather here a simple example. You should play with the lengths.:

\documentclass{article}
\usepackage{kantlipsum}
\usepackage{xpatch}
\xapptocmd\normalsize{%
 \abovedisplayskip=12pt plus 3pt minus 9pt
 \abovedisplayshortskip=0pt plus 3pt
 \belowdisplayskip=12pt plus 3pt minus 9pt
 \belowdisplayshortskip=7pt plus 3pt minus 4pt
}{}{}
\usepackage{amsmath}
\begin{document}
\kant[1]
\begin{gather}
  1 + 1 = 2
\end{gather}
\kant[1]
\begin{gather}
  1 + 1 = 2
\end{gather}
\kant[1]
\begin{subequations}
\begin{equation}
  1 + 1 = 2
\end{equation}
\end{subequations}
\kant[1]
\kant[1]
\end{document}
2
  • @User17670: There are no differences for gather or subequations Sep 1, 2012 at 13:54
  • @User17670: As duplicated is more correct because the MWE shows that the lengths will work for gather too. Sep 1, 2012 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .