2

I'm frequently using the following group code to reduce vertical space between some equations (with the equation, align, gather and other maths environment) and the text above it:

\begingroup\abovedisplayskip=0pt
    some equations in there
\endgroup

But instead of typing this group code each time by hand, how could I create a simple macro in the preamble to do the same? I'm guessing that the macro should be used like the following, but can it be simpler?

\eqlift
     some equations in there
\eqdown

Here's a MWE code that shows the problem, which I solve with the code above (only after compilation):

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage{lmodern}
\usepackage{amsmath}

\begin{document}

Blabla bla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla bla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla blabla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla blabla blabla bla bla blabla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}

\end{document}

And here's a preview of what it does: enter image description here

I often get some too large vertical space for any class, any font size or other configuration I've tried in the past (see equation (3) in the preview picture). The only way I know to solve this, is to insert the group code I've shown above.

  • 1
    \newenvironment{raiseequations}[1][0pt]{\setlength{\abovedisplayskip}{#1}}}{}? And then \begin{raiseequations}[<optional length>] ... equations ... \end{raiseequations}. – Henri Menke Dec 6 '19 at 1:55
  • 2
    Well, the spacing depends on the class you're using, the packages you load \dots, so, yes. If the spacing looks consistently 'goofy', that sounds like something is wrong and would be better fixed rather than asking for a sticking plaster to cover it up. – cfr Dec 6 '19 at 1:57
  • @cfr, I'm not sure of this. For any class and settings I used before, I often get this vertical blank space between some text and the equation below it. I believe that it's a well known problem with LaTeX, that cannot be solved in a consistent way without having to interfere from time to time. – Cham Dec 6 '19 at 2:01
  • Yes, but if you're doing it so often you want a special macro, that sounds like something askew. It might not be. Perhaps you just have clumpy content (I don't mean that to be offensive - some content is naturally clumpy, as in the case of images, diagrams, tables etc. and some disciplines tend to clumpier content than others). But it is worth making sure that's the case, I would think. Also, it is just easier for people to understand and play with - including users less familiar with LaTeX who might have the same problem. – cfr Dec 6 '19 at 2:11
  • 1
    @cfr, agreed. But I don't like the extra vertical space after the text (see equation (3) in the preview I've posted). I know how to reduce it (but only after compilation, so I can see the extra space that I cannot predict), and I would like to make it easier with a macro. The suggestion from Henri Menke above works well, but could it be simpler (without having to type \begin{...} \end{...})? – Cham Dec 6 '19 at 2:14
3

enter image description here

Normally TeX uses \abovedisplayskip above an equation, but if the last line of the previous paragraph is short then it uses \abovedisplayshortskip by default most classes set this to a shorter length and so the equation "tucks in" to the space left by the short line above.

The shortdisplayskip is used if the last line finishes 2em to the left of the equation, to make sure there is still a visual gap.

Your case (3) just happens to be very close to the cutoff, TeX is using the longer length the same as used in (4) but subjectively you want it to work like (1) and (2).

I offer two variants here.

Equations 5-8 show the setting when both lengths have the same value you then avoid the discontinuity as tex switches from one style to the other, but (8) ends up looking rather tight.

Equations 9-12 are set with the default settings as in your original, but the length of the last line of the third paragraph is made to look (to TeX) artificially shorter by inserting an arbitrary negative space. That causes TeX to insert the same space as for the first two paragraphs.

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage{lmodern}
\usepackage{amsmath}

\begin{document}

\section{Original}

Blabla bla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla bla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla blabla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla blabla blabla bla bla blabla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}

\section{use abovedisplayshortskip everywhere}

{
\setlength\abovedisplayskip{\abovedisplayshortskip}


Blabla bla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla bla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla blabla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla blabla blabla bla bla blabla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}

}

\section{abovedisplayshortskip in (3=11)}

Blabla bla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla bla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla blabla :\hspace{-2cm}\mbox{}
\begin{equation}
    y(x) = a \, x^2.
\end{equation}
Blabla bla blabla bla blabla blabla bla bla blabla :
\begin{equation}
    y(x) = a \, x^2.
\end{equation}


\end{document}
| improve this answer | |
  • See my comment above. Maybe you can do something with it. – barbara beeton Dec 6 '19 at 15:28
  • So, if I understand your answer, you suggest to add \hspace{-2cm}\mbox{} before an equation to solve the issue? The spacing under equation (11) appears to be too short. – Cham Dec 6 '19 at 23:09
  • @Cham the space after 11 is identical to the space after 10 an 9 – David Carlisle Dec 7 '19 at 1:02
  • 1
    @Cham actually I would take the default spacing, I don't think there is an issue to solve, but if, as you ask here you want an equation near the point where tex switches layout to use the shortdisplayskip setting, then the negative hspace is the most natural way to do that, – David Carlisle Dec 7 '19 at 1:04
  • 1
    @Cham if for some reason you want to use a negative vspace instead then the amount you want is \vspace{\glueexpr\abovedisplayshortskip-\abovedisplayskip} – David Carlisle Dec 7 '19 at 20:41

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.