# Scale tikzpicture to the remaining height of a beamer frame

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?

-
An inherent hurdle here is that beamer frames have their content vertically centred. Consequently, you'll have to typeset something flush to the bottom in order to obtain the remaining height of the frame. Moreover, \pagegoal and \pagetotal don't seem to be of help here in order to calculate the remaining "page" height. –  Werner Sep 3 '11 at 5:52
Related questions are How to define a figure size so that it consumes the rest of a page? and How to compute the remaining space on the current page. Both use \pagegoal and \pagetotal but I trust @Werner when he says they don't work with beamer, which changes a lot of TeX internals. –  Martin Scharrer Sep 9 '11 at 10:31
Did me answer work for you? If not please state what is still missing. Otherwise please consider accepting it. Thanks. –  Martin Scharrer Oct 4 '11 at 17:50

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}


-
+1 Super! zref is awezome. –  Werner Sep 9 '11 at 14:25