# How do I ask beamer to exactly fill up a slide?

Inspired by a recent question with a very similar sounding title, I would actually love to implement auto-magic vertical stretch for beamer slides (where, maybe unlike full documents, I think makes a lot of sense!).

I've been very interested in controlling the vertical spacing on items in a slide for a long time (to me the default looks too “cramped”), and following ideas such as these, I've also implemented some hacks to manually control the vertical spacing on a slide using only an option such as [wide=10pt] on the frame. This is better than manually peppering my slides with \medskip and \bigskips, and it kind of works, but not all the time (see below).

What I would love, however, is to have all of these done automatically for me, without having to manually tune the required amount of spacing on each slide. So, following the advice on the question from that first link, I came up with something that almost works, but still has plenty deficiencies.

For testing I'm using a document that looks like:

\documentclass{beamer}

\newcommand\stretchy{\only<2>{%
%  \addstretch{\baselineskip}% Doesn't look very nice
}}

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{A few paragraphs (with\only<1>{out} stretching)}
\stretchy

As any dedicated reader can clearly see, the Ideal of practical reason is a representation of the things in themselves.

I have shown elsewhere, the phenomena should only be used as a canon for our understanding.

The paralogisms of practical reason are what first give rise to the architectonic of practical reason.
\end{frame}

...


And the first few pages look like:

The full source is here and an annotated version of the generated pdf is here.

This approach, just like my previous hack, has several problems:

• Spacing around equation or center environments doesn't seem to be consistent with other spaces between paragraphs. Also, to me, it's kind of hard to figure out which lengths are the ones responsible for the extra space that I often get, having to resort, again, to manual hacks trying to “kill” the extra space.
• Beamer makes it very difficult to consistently modify spaces within different environments. Notoriously, itemize and columns environments reset those spacings, so nasty hacks are needed to pass spacing options, e.g., from a frame to an itemize. Sometimes I can make them work for specific combinations, but often in the future I'm prone to find more combinations which I hand't considered and break my desired spacing rules.
• Nested subitems are particularly problematic, just setting the same spacing rules at the beginning of each itemize block makes some of the spaces too big.
• In general, interactions between itemize, equation, and center environments produce—at least to me—somewhat unpredictable results.
• Stretching in a columns environment doesn't work at all.

Ideally what I would like is to simply have to say:

\begin{frame}[stretch]

... frame contents ...

\end{frame}


and then have all the contents in the frame nicely vertically stretched and filling up all the space in the slide, with minimum or no manual modifications on the slide content. Do you think we could implement something like that?

-

All the magic is in the definitions at the top of the file. The only unique things in my slide content itself is that: 1) I did not leave a blank line before and after $...$ equation construct; and 2) the \columnskip specification mentioned below.

Here I addressed normal text, equations, centering, center environment, itemize environment. EDITED to address columns environment. I have REEDITED to introduce the macros \stretchon and \stretchoff to make this process selectable. Just issue one of these commands between frames to change the current mode. I have also REEDITED to provide the redefined \item with an optional argument, as it should be.

Generally, the main thing is to redefine \par to add a \vfill after the \par. However, a few additional refinements are required. The first invocation of \item in an environment should just use the regularly defined \item, but then redefine \item to add a \vfill prior to subsequent \items. Environments like center and itemize also may need to reinvoke the \vfilled version of \par, either coming into the environment, leaving it, or both.

In my edit to address the columns environment, I determined that \vfill solutions seemed to have no effect, which must have something to do with the way the two columns are separately constructed and aligned. So my solution was to introduce a length \columnskip, which will be the \parskip introduced between items in the column environment and upon exiting that environment. Thus, for any particular slide, one may have to adjust it once or twice to get a good match to the remaining \vfills on the page

\documentclass{beamer}
\def\itemsymbol{$\blacktriangleright$}
\let\svpar\par
\let\svitemize\itemize
\let\svenditemize\enditemize
\let\svitem\item
\let\svcenter\center
\let\svendcenter\endcenter
\let\svcolumn\column
\let\svendcolumn\endcolumn
\def\newitem{\renewcommand\item[1][\itemsymbol]{\vfill\svitem[##1]}}%
\def\newpar{\def\par{\svpar\vfill}}%
\newcommand\stretchon{%
\newpar%
\renewcommand\item[1][\itemsymbol]{\svitem[##1]\newitem}%
\renewenvironment{itemize}%
{\svitemize}{\svenditemize\newpar\par}%
\renewenvironment{center}%
{\svcenter\newpar}{\svendcenter\newpar}%
\renewenvironment{column}[2]%
{\svcolumn{##1}\setlength{\parskip}{\columnskip}##2}%
{\svendcolumn\vspace{\columnskip}}%
}
\newcommand\stretchoff{%
\let\par\svpar%
\let\item\svitem%
\let\itemize\svitemize%
\let\enditemize\svenditemize%
\let\center\svcenter%
\let\endcenter\svendcenter%
\let\column\svcolumn%
\let\endcolumn\svendcolumn%
}
\newlength\columnskip
\columnskip 0pt

\begin{document}
\stretchon
\begin{frame}{A few paragraphs (with stretching)}

As any dedicated reader can clearly see, the Ideal of practical reason is a representation of the things in themselves.

I have shown elsewhere, the phenomena should only be used as a canon for our understanding.

The paralogisms of practical reason are what first give rise to the architectonic of practical reason.
\end{frame}
\begin{frame}{Displayed Equation (with stretching)}

As any dedicated reader can clearly see, the ideal of practical
reason is a representation of the things in themselves

I have shown elsewhere, the phenomena should only be used as a canon for our understanding.
$x^2 +y^2 = z^2$
The paralogisms of practical reason are what first give rise to the architectonic of practical reason.

Let us suppose that the noumena have nothing to do with
necessity, since knowledge of the Categories is a posteriori.
\end{frame}
\begin{frame}{\textbackslash centering}

As any dedicated reader can clearly see, the ideal of practical
reason is a representation of the things in themselves

{\centering
BEGINNING CENTERING. I have shown elsewhere, the phenomena should only be used as a canon for our understanding.

The paralogisms of practical reason are what first give rise to the architectonic of practical reason. ENDING CENTERING.

}
Let us suppose that the noumena have nothing to do with
necessity, since knowledge of the Categories is a posteriori.
\end{frame}
\begin{frame}{center Environment (extra space before/after env)}

As any dedicated reader can clearly see, the ideal of practical
reason is a representation of the things in themselves

\begin{center}
BEGINNING \{CENTER\}. I have shown elsewhere, the phenomena should only be used as a canon for our understanding.

The paralogisms of practical reason are what first give rise to the architectonic of practical reason. ENDING \{CENTER\}.
\end{center}

Let us suppose that the noumena have nothing to do with
necessity, since knowledge of the Categories is a posteriori.
\end{frame}
\begin{frame}{itemize environment}

As any dedicated reader can clearly see, the Ideal of practical reason is a representation of the things in themselves.

Begin itemize now

\begin{itemize}
\item[$\bullet$] I have shown elsewhere, the phenomena should only be used as a canon for our understanding.

\item The paralogisms of practical reason are what first give rise to the architectonic of practical reason.
\end{itemize}

Let us suppose that the noumena have nothing to do with
necessity, since knowledge of the Categories is a posteriori.
\end{frame}
\begin{frame}{columns environment}
I have shown elsewhere, the phenomena should only be used as a canon for our understanding.
\columnskip 2ex%
\begin{columns}[totalwidth=\linewidth]
\begin{column}{.5\linewidth}
xxx

yyy

zzz
\end{column}
\begin{column}{.5\linewidth}
qqq

rrr
\end{column}
\end{columns}
The paralogisms of practical reason are what first give rise to the architectonic of practical reason.

Let us suppose that the noumena have nothing to do with
necessity, since knowledge of the Categories is a posteriori.
\end{frame}
\end{document}


-
This is looking very good! A problem I've found, though, is that the first use of an \item within an itemize won't be able to read any optional arguments, e.g. I can't write \item<+-> for overlays. –  Juan A. Navarro Feb 8 at 15:25
I'm also working trying to turn this solution into something that could be individually selected as an option per slide. –  Juan A. Navarro Feb 8 at 15:26
See my updated gist, I think that items with subitems and equations or other environments still don't have the proper spacing. –  Juan A. Navarro Feb 8 at 15:42
@JuanA.Navarro I haven't had a chance to look at the several issues you raise, but I did REEDIT to provide \stretchon and \stretchoff to make the processes selectable and unselectable. –  Steven B. Segletes Feb 8 at 17:56
@JuanA.Navarro I have resolved the \item issue by providing the redefined \item with an optional argument. –  Steven B. Segletes Feb 8 at 18:45