7

Often in a frame (of beamer), I have some texts on the top and a resized tikzpicture on the bottom:

\begin{frame}
\frametitle{...}
some texts
...
some texts
\[\resizebox{!}{???}{
\begin{tikzpicture}
...
\end{tikzpicture}
}\]
\end{frame}

I am wondering how to determine the ??? part, to make the tikzpicture occupy the remaining part of the frame, so that the total height of picture plus text occupies the whole frame.

Does anyone know how to do that?

Martin Scharrer
  • 262,582
SoftTimur
  • 19,767

1 Answers1

7

You can use zref to measure the remaining space by saving the bottom position of the text and the one of the bottom of the frame. The following code works for me. It requires two runs after each change of text. It seems to work well with different themes. If you want the image centered uncomment the \centering. I added a lower margin to not have it touch the bottom edge. You could also use a center environment which adds (rather large IMHO) margins by itself if you want.

Note that the environment restofframe can be used multiple times and all instances on one slide will share the remaining space equally.

\documentclass{beamer}
\usetheme{Berlin}

\usepackage{tikz}
\usepackage{zref-savepos}

\newcounter{restofframe}
\newsavebox{\restofframebox}
\newlength{\mylowermargin}
\setlength{\mylowermargin}{2pt}

\newenvironment{restofframe}{%
    \par%\centering
    \stepcounter{restofframe}%
    \zsavepos{restofframe-\arabic{restofframe}-begin}%
    \begin{lrbox}{\restofframebox}%
}{%
    \end{lrbox}%
    \setkeys{Gin}{keepaspectratio}%
    \raisebox{\dimexpr-\height+\ht\strutbox\relax}[0pt][0pt]{%
    \resizebox*{!}{\dimexpr\zposy{restofframe-\arabic{restofframe}-begin}sp-\zposy{restofframe-\arabic{restofframe}-end}sp-\mylowermargin\relax}%
        {\usebox{\restofframebox}}%
    }%
    \vskip0pt plus 1filll\relax
    \mbox{\zsavepos{restofframe-\arabic{restofframe}-end}}%
    \par
}

\begin{document}

\begin{frame}
\frametitle{Title}
some texts

some texts

some text

some text

\begin{restofframe}
\begin{tikzpicture}
    \draw (0,0) -- (1,1);
    \draw (0,1) -- (1,0);
\end{tikzpicture}%
\end{restofframe}
\end{frame}

\begin{frame}
\frametitle{Title}
\framesubtitle{Subtitle}
some texts

some texts

some text

some text

\begin{restofframe}
\begin{tikzpicture}
    \draw (0,0) -- (1,1);
    \draw (0,1) -- (1,0);
\end{tikzpicture}%
\end{restofframe}
\end{frame}

\begin{frame}
\frametitle{Title}
\framesubtitle{Subtitle}
some texts

some texts

\begin{restofframe}
\begin{tikzpicture}
    \draw (0,0) -- (1,1);
    \draw (0,1) -- (1,0);
\end{tikzpicture}%
\end{restofframe}

some text

some text

\end{frame}

\end{document}

Result

Martin Scharrer
  • 262,582