[Tex/LaTex] How to determine the height of a beamer block

beamerheightoverlays

To keep content from jumping between slides in a beamer presentation, I would like to use an overlayarea environment. By trial and error, one can determine the appropriate amount of space to reserve. However, I would like to determine it automatically. To do this, I want to determine the height of one or more block environments.

In the following example, the position of "Some text" changes between the first and second slides. I would like for it not to move. To that end, I would like to enclose Block 1 and Block 2 in an overlayarea. I want to determine the heights of Block 1 and Block 2, as well as the vertical space between them, and then use that as the height parameter for the overlayarea.

\documentclass{beamer}

\mode<presentation>
{
  \usetheme{Frankfurt}
}

\begin{document}

\begin{frame}
 Some text

 \only<1>{
  \begin{block}{Block 1}
   Other text
  \end{block}

  \begin{block}{Block 2}
   Still more text
  \end{block}
}

  \only<2>{
    \begin{block}{Block 3}
     Yet more text
    \end{block}
}
\end{frame}

\end{document}

This is what I want to end up with:

\documentclass{beamer}

\mode<presentation>
{
  \usetheme{Frankfurt}
}

\begin{document}

\begin{frame}
 Some text

 \begin{overlayarea}{\textwidth}{\myheight} %\myheight is the quantity to be determined
   \only<1>{
  \begin{block}{Block 1}
   Other text
  \end{block}

  \begin{block}{Block 2}
   Still more text
  \end{block}
}

  \only<2>{
    \begin{block}{Block 3}
     Yet more text
    \end{block}
}
 \end{overlayarea}
\end{frame}

\end{document}

N.B.: This question is about how to find the width of a block, but I have not found anything about finding the height.

Best Answer

You can do it by boxing the content and then adding the depth and height of the box to obtain the total height:

\setbox0=\vtop{%
  \begin{block}{Block 1}
   Other text
  \end{block}%
}
\setlength{\myheight}{\ht0}%
\addtolength{\myheight}{\dp0}%

enter image description here

Code:

\documentclass{beamer}

\mode<presentation>
{
  \usetheme{Frankfurt}
}

\newlength{\myheight}
\begin{document}
\setbox0=\vtop{%
  \begin{block}{Block 1}
   Other text
  \end{block}%
}
\setlength{\myheight}{\ht0}%
\addtolength{\myheight}{\dp0}%

\begin{frame}
 Some text

 \begin{overlayarea}{\textwidth}{\myheight} %\myheight is the quantity to be determined
   \only<1>{
  \begin{block}{Block 1}
   Other text
  \end{block}

  \begin{block}{Block 2}
   Still more text
  \end{block}
}

  \only<2>{
    \begin{block}{Block 3}
     Yet more text
    \end{block}
}
 \end{overlayarea}
\end{frame}

\end{document}