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.
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.
\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.
\expandafter
s, 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
\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.
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}
subequations
andgather
it appears that you are usingamsmath
. (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 ofamsmath
; unfortunately, the overhaul has not yet been firmly scheduled.equation
andalignment
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
?