equation变成gather

equation变成gather

尽管也有类似的问题这里那里,我找不到令人满意的答案。我试图在 beamer 中使文本、方程式和列表之间的垂直间距一致/相同。更确切地说,我正在查看以下之间的垂直间距:

  1. 文本后跟公式(反之亦然)
  2. 方程式后面跟着一个列表

虽然第 1 点中的空间完全没问题,但我很难理解第 2 点中发生的事情:等式后面跟着列表会产生太大的空间,而列表后面跟着等式会产生太小的空间。下面可以找到 MWE。

我希望在序言中一劳永逸地解决这个问题,而不必在这两个环境之间每次交互时手动添加一些代码。但我看不到明显的参数需要更改:

  • 使用参数\abovedisplayskip \belowdisplayskip可以解决点 2 的问题,但会弄乱点 1 的间距。而且我不想“本地”执行此操作。
  • 在每个列表前添加一些(负)垂直空间\vspace{-\baselineskip}将会弄乱列表和文本之间的间距。

我觉得这里的公式和条目环境都设置为在它们周围添加一些垂直间距,并且这些间距在彼此相邻时会累积。也许我错了,但我记得曾经读过 TeX 中有一个“条件空间”的概念,意思是需要插入一个空间,但条件是生成的空间(与其他命令组合后)不会大于给定的阈值。这可能是我需要的吗?

任何帮助都将不胜感激。以下是 MWE:

\documentclass{beamer}

\begin{document}

\begin{frame}{What I'm satisfied with}
Here is an equation, surrounded by two sentences.
\begin{equation*}
e^x \Vert \nabla f(x) \Vert \leq f(x^k) - \inf f
\end{equation*}
We see that the spacing above and below is the same.

\bigskip \hrule \bigskip

Now we look at equations inside a list.
\begin{itemize}
    \item Some text in the first item.
    \begin{equation*}
        e^x \Vert \nabla f(x) \Vert \leq f(x^k) - \inf f
    \end{equation*}
    Some more text, still in the first item. Good spacing.
    \item Some text in the second item.
    \begin{equation*}
        e^x \Vert \nabla f(x) \Vert \leq f(x^k) - \inf f
    \end{equation*}
    \item Some text in the third item. Good spacing.
\end{itemize}
\end{frame}

\begin{frame}{What I'm not satisfied with}
Now an equation followed by a list.
\begin{equation*}
e^x \Vert \nabla f(x) \Vert \leq f(x^k) - \inf f
\end{equation*}
\begin{itemize}
    \item We see a superfluous space between the equation and the list.
\end{itemize}

\bigskip \hrule \bigskip

Now an equation preceded by a list.
\begin{itemize}
    \item Here is an itemize environment, with one item.
\end{itemize}
\begin{equation*}
e^x \Vert \nabla f(x) \Vert \leq f(x^k) - \inf f
\end{equation*}
The space above and below is roughly the same, but it is a smaller spacing than in the first examples.
\end{frame}

\end{document}

我感到满意的是

我不满意的地方

答案1

这是一个解决方案:

  1. 带有列表补丁beamer

  2. 使用gather*(来自amsmath包)而不是equation*

注意:列表最后一项中的方程式与列表后紧接着的方程式之间只存在一个非常小的额外空格!

\documentclass{beamer}

% patch for lists with `beamer`
\usepackage{etoolbox}
\makeatletter
\pretocmd{\itemize}{\ifhmode\unvbox\voidb@x\fi}{}{}
\pretocmd{\enumerate}{\ifhmode\unvbox\voidb@x\fi}{}{}
\makeatother

% use `gather*` instead of `equation*`
\usepackage{amsmath}

\begin{document}

\begin{frame}{What I'm satisfied with}
  Here is an equation, surrounded by two sentences.
  \begin{gather*}
    e^x \Vert \nabla f(x) \Vert \leq f(x^k) - \inf f
  \end{gather*}
  
  We see that the spacing above and below is the same.
  
  \bigskip \hrule \bigskip
  
  Now we look at equations inside a list.
  \begin{itemize}
  \item Some text in the first item.
    \begin{gather*}
      e^x \Vert \nabla f(x) \Vert \leq f(x^k) - \inf f
    \end{gather*}
    Some more text, still in the first item. Good spacing.
  \item Some text in the second item.
    \begin{gather*}
      e^x \Vert \nabla f(x) \Vert \leq f(x^k) - \inf f
    \end{gather*}
  \item Some text in the third item. Good spacing.
  \end{itemize}
\end{frame}

\begin{frame}{What I'm not satisfied with}
  Now an equation followed by a list.
  \begin{gather*}
    e^x \Vert \nabla f(x) \Vert \leq f(x^k) - \inf f
  \end{gather*}
  \begin{itemize}
  \item We see a superfluous space between the equation and the list.
  \end{itemize}
  
  \bigskip \hrule \bigskip
  
  Now an equation preceded by a list.
  \begin{itemize}
  \item Here is an itemize environment, with one item.
  \end{itemize}
  \begin{gather*}
    e^x \Vert \nabla f(x) \Vert \leq f(x^k) - \inf f
  \end{gather*}
  
  The space above and below is roughly the same, but it is a smaller spacing than in the first examples.
\end{frame}

\end{document}

第一张幻灯片

第二张幻灯片

equation变成gather

为了获得相同的结果而不替换equationby gather(和equation*by gather*),您可以重新定义equationandequation*环境:

% patch for lists with `beamer`
\usepackage{etoolbox}
\makeatletter
\pretocmd{\itemize}{\ifhmode\unvbox\voidb@x\fi}{}{}
\pretocmd{\enumerate}{\ifhmode\unvbox\voidb@x\fi}{}{}
\makeatother

% `equation` becomes 'gather'
\usepackage{amsmath}
\csletcs{equation}{gather}
\csletcs{endequation}{endgather}
\csletcs{equation*}{gather*}
\csletcs{endequation*}{endgather*}

相关内容