1

I am writing some sentences which contain numbered displayed equations in the middle, like this one:

|  Consider the relationship:      |
|      EQUATION                 (1)|
|where x is ... and y is ...       |
|                                  |
|  This is a new paragraph which   |
|ends with the following:          |
|      EQUATION                 (2)|
|                                  |
|  And this is the last paragraph, |
|followed by some equations which  |
|are not part of it.               |
|                                  |
|      EQUATIONS                (3)|
|                                  |
|  The end.                        |

This is the code, with empty line between paragraphs:

Consider the relationship:
\begin{equation} ... \end{equation}
where x is ... and y is ...

This is a new paragraph which ends with the following:
\begin{equation} ... \end{equation}

And this is the last paragraph, followed by some equations which are not part of it.

\begin{equation} ... \end{equation}

The end.

I'd like to reduce the space between the equation and the text, but only in those cases in which the equation is in the middle of the sentence (note the vertical spacing and the paragraph indentations in the example above). Is there any way to do that, whitout changing global spacing like here?

The ideal solution would be something that recognize whether the equation is part or a paragraph or not (i.e. based on the blank lines between two paragraphs, like the indentation). Alternatively, a command to insert before, inside or before+after the equation (and gathered, align, ...) environments, or a new environment like \begin{NoSpaceEquation} ... \end{NoSpaceEquation}, is fine too.

I'm not looking for solutions like a global space reduction, which would need to manually add space before and after isolated equations. The solution should affects only the equations inside a paragraph.

PS: I am using mathtools.

Thank you!

  • 1
    Just remove spaces before \begin{equation} and after \end{equation}. – Roboticist Apr 24 '18 at 16:58
  • @Roboticist that's exaclty what I've done in the paragraph "Consider the relationship...", at it does not work (if it does, the difference is quite minimal and the space is still too large) – Taekwondavide Apr 24 '18 at 17:16
  • 2
    never leave a blank line before equation (that is not vertical space it is a spurious empty line of text) – David Carlisle Apr 24 '18 at 17:22
  • @DavidCarlisle isn't that like, semantically speaking, putting the equation in a separate paragraph? I mean, something like: Text: \\ Equation (no blank line) vs. Text. \par Eqation (blank line) – Taekwondavide Apr 24 '18 at 17:36
  • 2
    never use either \\ or a blank line (or \par) before a math display, TeX simply does not support that. – David Carlisle Apr 24 '18 at 18:35
2

You can use the \useshortskip command from nccmath (just before the equation) or \SwapAboveDisplaySkip (at the very beginning of an amsmath environment):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools, nccmath}

\begin{document}

In the first place, consider the relationship:
\begin{equation}\textit{A first equation} \end{equation}
where x is ... and y is ...

This is a new paragraph which ends with the following equation:\useshortskip
\begin{equation}\textit{Another equation} \end{equation}

This is another paragraph which ends with an AmSmath environment:
\begin{gather}\SwapAboveDisplaySkip\textit{Another equation} \end{gather}

And this is the last paragraph, followed by some equations which are not part of it.

\begin{equation}\textit{Still another equation}.\end{equation}

The end.

\end{document} 

enter image description here

To reduce the spacing above and below an equation, we can patch an internal command of nccmath, but the following text must not start a new paragraph:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools, nccmath}

\usepackage{xpatch}
\xpatchcmd{\NCC@ignorepar}{%
\abovedisplayskip\abovedisplayshortskip}
{%
\abovedisplayskip\abovedisplayshortskip%
\belowdisplayskip\belowdisplayshortskip}
{}{}

\begin{document}

In the first place, consider the relationship:
\begin{equation}\textit{A first equation} \end{equation}
where x is ... and y is ...

This is a new paragraph which ends with the following equation:\useshortskip
\begin{equation}\textit{Another equation}\text{(spacing with \texttt{\textbackslash useshortskips})}\end{equation}

And this is the last paragraph, followed by some equations which are not part of it.

\begin{equation}\textit{Still another equation}.\end{equation}

The end of this very exhaustive test.

\end{document} 

enter image description here

  • Thank you! Unfortunately \SwapAboveDisplaySkip gives me a lot of errors (maybe for some reasons like this, I use a lot of packages). I tried \useshortskip but it only reduces the space before, even if I put it after \end{equation}. Is there any solution for the space after? – Taekwondavide Apr 24 '18 at 17:29
  • @Taekwondavide: I've posted a solution with a patch of nccmath . Is it more like what you want? – Bernard Apr 24 '18 at 19:12
  • it's not clear to me how the patch work. Does it affect any equation or the ones with \SwapAboveDisplaySkip? Anyway I added the patch to my preamble and I don't notice significant changes. With reference to both of your screenshots, what I need is to have in the first paragraph "In the first place..." to have before and after eqn (1) the same space that there is before eqn (2), but \useshortskips only works with the space before – Taekwondavide Apr 26 '18 at 15:05
  • Sorry, I made a mistake, now I can see the space reduction below, anyway the space below is still larger than the space above. Is there any way to have (almost) the same reduced space above and below? – Taekwondavide Apr 26 '18 at 15:47
  • In the patche (which is only for \useshortskip, you can replace \belowdisplayskip\belowdisplayshortskip with, say, \belowdisplayskip 0.5\belowdisplayshortskip, or even\belowdisplayskip\z@skip, for instance, but I find it's too tight. It's also a semantic question: is what follows the continuation of the equation or not? – Bernard Apr 26 '18 at 15:59

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.