1

Currently I am updating and extending my beamer themes. Thereby I also want to solve a spacing problem, which is sometimes quite annoying.

Think of the following example:

\documentclass[t]{beamer}
%
\newcommand{\testcontent}[2]{%
    \frametitle{Frame #2}
    Text\medskip\par
    Itemize:%
    \begin{itemize}
    \item a%
    \item b%
    \item c%
    \end{itemize}
    \begin{figure}
    \framebox(300,#1){Height = #1 units}%
    \end{figure}
}
%
\begin{document}
%
\begin{frame}
\testcontent{150}{1}%
\end{frame}
%
\begin{frame}
\testcontent{50}{2}%
\end{frame}
%
\begin{frame}
\testcontent{150}{3}%
\vspace{0ex plus 1fil minus 1fil}%
\end{frame}
%
\end{document}

The example creates the following three frames. Open them in separate tabs to see the differences in vertical spacing:

Frame 1 Frame 2 Frame 3

In the first frame the defined height of the figure forces LaTeX to stretch (shrink) the vertical spaces of \medskip, itemize and figure. This can be seen if compared with the second frame, where the height of the figure is smaller and the vertical spaces are not stretched.

So I was looking for a solution to avoid the stretching of vertical spaces and consequently to have no jumping text lines when switching between frames. I found that someone redefined the corresponding lenghts to have no plus minus glue, but this did not work in my case or I missed to change some lengths.

So I came up with the \vspace{0ex plus 1fil minus 1fil} command in the third frame. This avoids stretching of the other verticals spaces, but gives no warning if the frame content does not fit on the frame. Another problem is, that I have to add this line manually to each frame end. I tried to automate this using \patchcmd for \beamer@collect@@body, but this also did not work.

Now to my questions:

  1. Is there another way to avoid the described stretching of vertical spaces and to have constant vertical spaces independent of the frame content?
  2. If there is no other solution then I used in the third frame above, is it possible to add the command automatically to each frame end?

Thank you very much for your help.

  • If you are open to use one frame instead of three, you can have a look at only<> command. In your case you could use it in the first frame as only<1> for the content of first... then only<2> for the second and 'only<3>' for the third... This works if you really want the above text to be the same for all your 3 frames... If not you can change it too with alt<1>{text for frame 1}{empty or text for others} etc – koleygr Sep 17 '17 at 20:39
  • Please see my comment to the answer of @samcarter. – Michael Sep 20 '17 at 17:19
1

For "frames with only slightly varying content" I would not use separate frames, but slides of the same frame. To get the same shrinking between the slides, you can reserve the required space for your largest figure with the overlayarea environment.

\documentclass[t]{beamer}

\begin{document}

\begin{frame}
    \frametitle<1>{Frame 1}
    \frametitle<2>{Frame 2}
    Text\medskip\par
    Itemize:%
    \begin{itemize}
    \item a%
    \item b%
    \item c%
    \end{itemize}
    \begin{overlayarea}{300pt}{150pt}
      \begin{figure}
        \only<1>{\framebox(300,150){Height = 150 units}}
        \only<2>{\framebox(300,50){Height = 50 units}}
      \end{figure}
    \end{overlayarea}
\end{frame}

\end{document}
  • It would be better to write "frames with varying content, but same layout" or leave it away. I edited my question. I know the \only command and the overlayarea environment. My example only should show the stretching of vertical spaces and consequently jumping text lines when switching frames. My question is more about how to remove this stretching. – Michael Sep 20 '17 at 17:14
0

Here is an answer according to my answer here: https://tex.stackexchange.com/a/389647/120578

\documentclass[t]{beamer}
%
\usepackage{calc}
\newdimen\mycurrentheight
\newdimen\mymaxheight
\newdimen\myspace
\newdimen\zerodimen
\newsavebox{\mybox}

\def\keepHeight#1{
\setbox\mybox\vbox{#1}
\setlength{\mycurrentheight}{\ht\mybox+\dp\mybox}
\addspace{\mycurrentheight}
\usebox{\mybox}
\vskip \myspace
}


\def\addspace#1{
\ifdim\mycurrentheight>#1
\let\mymaxheight=\mycurrentheight
\let\myspace=\zerodimen
\else
\let\myspace=\zerodimen
\advance \myspace by \mymaxheight
\advance \myspace by -\mycurrentheight
\fi
}

\newcommand{\testcontent}[2]{%
    \frametitle{Frame #2}
    Text\medskip\par
    Itemize:%
    \begin{itemize}
    \item a%
    \item b%
    \item c%
    \end{itemize}
    \keepHeight{\begin{figure}
    \framebox(300,#1){Height = #1 units}%
    \end{figure}}
}
%
\begin{document}
%
\begin{frame}
\testcontent{140}{1}%
\end{frame}
%
\begin{frame}
\testcontent{50}{2}%
\end{frame}
%
\begin{frame}
\testcontent{140}{3}%
%\vspace{0ex plus 1fil minus 1fil}%
\end{frame}
%
\end{document}

I am not really sure if this is what you really want. I have created the command \keepheight{} and used it in your \testcontent.

I suppose we can manipulate it to your wants but I am not sure about that.

Give it a try!

Edit

Adding screenshots after OP's comment:

enter image description here

enter image description here

enter image description here

  • I tested it and so far I can see, I get the same result as with my \vspace{0ex plus 1fil minus 1fil} command. It does not disable stretching of vertical spaces in a general manner, as I want it to have. – Michael Sep 20 '17 at 17:44
  • @Michael Are you sure you compiled the code I gave you? I added screenshots and I can not see the problem. If the code you tested it is different and my answer doesn't work please edit your question to reproduce the problem. – koleygr Sep 20 '17 at 18:03
  • Yes, I compiled it and tested it also width Height = 150 units. The result is the same when using \vspace{0ex plus 1fil minus 1fil} for every frame. You used \keepHeight also for every frame. – Michael Sep 20 '17 at 18:36
  • Ok... Probably I can not understand what you want to do... You see that mine 140units are almost outside of the page... but you use 150... My code just keeping the same height for everything in my \keepHeight{} command. May be your vspace does the same... but I still don't get your point. – koleygr Sep 20 '17 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.