我强制使用两个串联的数学环境,这将带来很大的空间,我不喜欢,我看到了这个答案,他使用\\[-1ex]
我不想对每个方程都使用这种方法(我有很多方程),那么有没有办法可以减少整个文档中两个环境之间的空间?
这是一个简单的例子
\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}
答案1
应避免连续显示数学。如果您确实必须将对齐显示数学和非对齐内容分组,请使用单个显示数学环境(此处为gather*
),并使用内部数学环境执行对齐(此处为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}
答案2
您可以嵌套align
(gather
而不是反过来)。在示例代码中,我使用了编号方程,但添加*
将产生预期结果。
\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}
如果两个环境之间有文本,只需输入即可,中间无需留空行。
\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}
一个空白行能跟随显示,但前提是真正开始新的段落。
答案3
我不推荐它,但是这会给你你想要的东西......
\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}