Controlling vertical spaces in Latex beamer

2024年2月13日

Oftentimes, you don’t have to worry about verfical spaces in Latex files, especially when using document class article. Document classes have already defined best or industry standard spaces. Nevertheless, if you are producing slides with the beamer class, sometimes you just want to squeeze in a bit of text or images. In that case, you may want to reduce vertical spaces in a frame.

Spaces before and after figure

The figure environment is defined by the beamer class, implemented as \trivlist, different from figure in LaTeX.

The figure environment in beamer reads the length \parskip and \topsep.

Space occupied by overlayarea

The overlayarea environment introduces vertical space even if it’s used as \begin{overlayarea}{0pt}{0pt}. To cancel the extra space, issue \offinterlineskip (turn off from now on) or \nointerlineskip (for this paragraph only).[1]

Note, \offinterlineskip and \nointerlineskip may not work when the slides are compiled with the handout option or show only notes. Then you can hide this part with \mode{..}.

Space occupied by tikzpicture

The tikzpicture environment with the overlay option, ie. \begin{tikzpicture}[remember picture,overlay], still takes up space.

There are two ways to remove the space. The first method is the same as overlayarea, that is \offinterlineskip or \nointerlineskip. The second method is to put \begin{tikzpicture} within a paragraph.

\begin{tikzpicture} cannot start a paragraph, but within an existing paragraph, such as Hello\begin{tikzpicture}[overlay].

\begin{figure}
\begin{subfigure}{.9\textwidth}
your main content
\end{subfigure}
\begin{subfigure}{1pt}
% tikzpicture with overlay occupies the space of one character.
\begin{tikzpicture}[remember picture,overlay]
...
\end{tikzpicture}
\end{subfigure}
\end{figure}

Debugging

You can use package unravel to debug a command.

参考资料

  1. samcarter. overlayarea takes space even with height 0. . 2023-11-30 [2024-02-14].