9

Even though similar questions arose here and there, I cannot find a satisfying answer to my problem. I am trying to have consistent/identical vertical spacing between text, equations and lists in beamer. More exactly, I am looking at the vertical spacing between:

  1. text followed by equation (and vice versa)
  2. equation followed by a list

While the spaces in point 1. are perfectly fine, I have trouble understanding what happens in point 2. : an equation followed by a list produces a too large space, and a list followed by an equation produces a too small space. A MWE can be found below.

What I would like to do is to fix this once and for all in the preamble, and not having to add some code manually every time there is an interaction between those two environments. But I see no obvious parameters to change :

  • playing with the parameters \abovedisplayskip \belowdisplayskip will solve the problem for point 2. but will mess up the spacing for point 1. And I do not want to do that "locally".
  • Adding some (negative) vertical space \vspace{-\baselineskip} before every list will mess up the spacing wetween lists and text.

I feel like here both equation and itemize environements are set to to add some vertical spacing around them, and that these spaces cumulate when next to each other. Maybe I am wrong but I remember reading once that in TeX there is a concept of "conditional space", meaning a space which needs to be inserted but to the condition that the resulting space (after combination with other commands) will not be larger than a given threshold. Could it be what I need?

Any help would be highly appreciated. Here is a 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}

what i'm satisfied with

what i'm not satisfied with

Guillaume
  • 153
  • 8
  • This would require me to change my lists everywhere manually, which is what I am trying to avoid. – Guillaume Sep 16 '21 at 09:12
  • Changing all the lists is not an option since the spacing issue holds only when they are surrounded with equations. Moreover, I do not want in the future to have to specify an option for every list I type. It is a much more desirable solution to fix once and for all the behavior of lists in the preamble. – Guillaume Sep 16 '21 at 14:07
  • 2
    Try https://tex.stackexchange.com/a/640156/14500 – Paul Gaborit Jun 14 '22 at 14:28
  • Thanks! It solves my first problem (equation-then-list)! But it does nothing on the second one (equation after a list environment). Any idea would be welcome. – Guillaume Jun 14 '22 at 14:41
  • After a list environment, you can use gather* (from amsmath package). – Paul Gaborit Jun 15 '22 at 05:54

1 Answers1

7

Here is a solution:

  1. with a patch for lists in beamer.

  2. using gather* (from amsmath package) instead of equation*

Note: An equation in the last item of a list is only distinguished from an equation just after a list by a very small extra space!

\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}

first slide

second slide

equation becomes gather

To get the same result without replacing equation by gather (and equation* by gather*), you can redefine the equation and equation* environments:

% 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}

Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
  • Nice! Unfortunately using gather instead of equation is out of the question for me (I already have a lot of files and I just want to change the template). Maybe a solution would be to redefine "equation" and its starred version as "gather"? – Guillaume Jun 20 '22 at 09:08
  • @Guillaume I added the code avoiding manual replacement (without worrying about possible side effects). – Paul Gaborit Jun 20 '22 at 09:28
  • Thanks! You solution is good enough for me. – Guillaume Jun 20 '22 at 12:53
  • This patch worked as intended, but seems to break down in combination with the paralist package. – moro11 Oct 11 '23 at 12:43
  • @moro11 By default, paralist does not work with beamer. In fact, beamer must use the beamerpatchparalist package. Indeed, I have not tested my patch with this already fragile combination. – Paul Gaborit Oct 11 '23 at 19:36