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 \bigskip
s, 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{\addstretch}[1]{\addtolength{#1}{\fill}}
\newcommand\stretchy{\only<2>{%
% \addstretch{\baselineskip}% Doesn't look very nice
\addstretch{\abovedisplayskip}%
\addstretch{\abovedisplayshortskip}%
\addstretch{\belowdisplayskip}%
\addstretch{\belowdisplayshortskip}%
\addstretch{\parskip}%
}}
\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
orcenter
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
andcolumns
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
, andcenter
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?
Best Answer
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\item
s. Environments likecenter
anditemize
also may need to reinvoke the\vfill
ed 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 thecolumn
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\vfill
s on the page