7

I force to use two math environments in series, this will present a big space that I don't like, I saw this ansewer, he uses \\[-1ex] I don't want to use this method for each equation (I have a lot of equations), so is there any way to reduce the space between the two environments for the whole document?

Here is a simple example

\documentclass[a4paper,14pt]{extreport}
\usepackage{amsmath}
\begin{document}
\begin{align*}
     r &= \sqrt{x^2 + y^2} \\
     f &= m a \\
     A = \frac{\pi}{4} d^2
\end{align*}  
\begin{align*}
     \frac{\partial P}{\partial \theta} = \frac{P_{(i+1,j)} - P_{(i-1,j)}}{2 \Delta\theta}
\end{align*}
\end{document}

enter image description here

4
  • 5
    You should avoid using successive display math environments. Why not combine them into one?
    – Werner
    Aug 21 '16 at 1:21
  • this example is simple and can be combined, but I have many cases that I forced to separate the equation in two or more environment, so I asked for a solution for such case. Aug 21 '16 at 1:26
  • I can't imaging any case which force me to wrote series of successive equation which I can't merge it in one math environment (offered by amsmath/mathtools) . From reader side view math construct of number (different?) math environments is difficult to read and follow.
    – Zarko
    Aug 21 '16 at 1:36
  • Never use align for a single equation: there's equation for that.
    – egreg
    Aug 21 '16 at 7:40
8

Consecutive math displays should be avoided. If you really must group aligned display math and non-aligned content, use a single display math environment (here, gather*) and use an internal math environment to perform the alignment (here, aligned):

\documentclass[a4paper,14pt]{extreport}
\usepackage{amsmath}
\begin{document}
\begin{gather*}
\begin{aligned}
     r &= \sqrt{x^2 + y^2} \\
     f &= m a \\
     A &= \frac{\pi}{4} d^2
\end{aligned} \\
     \frac{\partial P}{\partial \theta} = \frac{P_{(i+1,j)} - P_{(i-1,j)}}{2 \Delta\theta}
\end{gather*}
\end{document}

enter image description here

1
4

You can nest align in gather (not the other way around). In the example code I use numbered equations but adding the * will produce the expected result.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

The the basic solution consists in nesting \texttt{align} in \texttt{gather}
as shown below
\begin{gather}
  \begin{align}
  r &= \sqrt{x^2 + y^2} \\
  f &= m a \\
  A &= \frac{\pi}{4} d^2
  \end{align}\\
\frac{\partial P}{\partial \theta} = \frac{P_{(i+1,j)} - P_{(i-1,j)}}{2 \Delta\theta}
\end{gather}
Adding some phantoms also fixes the vertical spacing
\begin{gather}
  \begin{align}
  r &= \sqrt{x^2 + y^2}  \vphantom{\frac{1_{\mathstrut}}{2}}\\
  f &= m a               \vphantom{\frac{1_{\mathstrut}}{2}}\\
  A &= \frac{\pi}{4} d^2 \vphantom{\frac{1_{\mathstrut}}{2}}
  \end{align}\\
\frac{\partial P}{\partial \theta} = \frac{P_{(i+1,j)} - P_{(i-1,j)}}{2 \Delta\theta}
\end{gather}

\end{document}

enter image description here

If you have text between the two environments, just type it in, without blank lines in between.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

If we have some word between the two environments, it's very easy:
\begin{align}
  r &= \sqrt{x^2 + y^2} \\
  f &= m a \\
  A &= \frac{\pi}{4} d^2
\end{align}  
where
\begin{equation}
\frac{\partial P}{\partial \theta} = \frac{P_{(i+1,j)} - P_{(i-1,j)}}{2 \Delta\theta}
\end{equation}
The important thing is not leaving blank lines before and after the math display
environments.

\end{document}

A blank line can follow a display, but only if a really new paragraph begins.

enter image description here

9
  • thanks for the answer, sometimes I need to write 'where' between the two environments, I want the word has no indent, how could I do that? Aug 21 '16 at 15:47
  • @MuhammadAbdulrasool You need nothing special, I'll add the code.
    – egreg
    Aug 21 '16 at 15:50
  • Thanks, but how can it be written inside the first environment (without indent) as in your first code? Aug 21 '16 at 17:06
  • I tried this \text{where} \\ , but there is a lot of white space, I change the gather to align but still the same. Aug 21 '16 at 17:44
  • @MuhammadAbdulrasool I don't understand what you are trying to do; the “where” word should go where I showed.
    – egreg
    Aug 21 '16 at 18:01
1

I don't recommend it, but this gives you what you appear to want...

\documentclass[a4paper,14pt]{extreport}
\usepackage{amsmath}

\begin{document}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
    \begin{align*}
        r &= \sqrt{x^2 + y^2} \\
        f &= m a \\
        A &= \frac{\pi}{4} d^2
    \end{align*}%  
\begin{align*}
        \frac{\partial P}{\partial \theta} = \frac{P_{(i+1,j)} - P_{(i-1,j)}}{2 \Delta\theta}
    \end{align*}
\end{document}
3
  • 1
    Won't this also remove the space before the first environment and after the last?
    – cfr
    Aug 21 '16 at 1:40
  • (1) second math environment sesms to be gather*, (2) as mentioned @cfr, this changes is acceptable only locally, so you need to design a group in which your changes is valid. And I agree with you, that this is not recommended solution :-).
    – Zarko
    Aug 21 '16 at 1:47
  • Yes, just group them.
    – JPi
    Aug 21 '16 at 1:54

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.