# Vertical centering inside an overprint

Is there an "easy" way to vertically center stuff in an overprint environment?

Based on the current answer, this is my test document

\documentclass{beamer}
\usepackage{listings}
\long\def\opcenter#1{\vfill\smash{\begin{minipage}[c]{\linewidth}#1\end{minipage}}}
\begin{document}
\begin{frame}[fragile]
\begin{overprint}
\onslide<1>
\opcenter{A short paragraph}
\onslide<2>
\opcenter{A\\
longer\\
paragraph\\
with\\
a\\
few\\
lines}
\onslide<3>
\opcenter{
\begin{block}{Title}
A block \\
with\\
a\\
few lines
\end{block}
}
\onslide<4>
\opcenter{
One paragraph

Plus something else
}
\onslide<5>
\opcenter{
\begin{lstlisting}
And verbatim stuff
\end{lstlisting}
}
\end{overprint}
\end{frame}
\end{document}


And the problem now is with paragraph breaks (a replacement for \smash?) and verbatim content (listings).

-

The idea is to use \smash to hide the height of the text, use \vfills to center vertically and then use minibox to get line breaking in the text.

You could also use minipage in place of minibox, but the former requires specifying the width.

\documentclass{beamer}
\usepackage{minibox}
\begin{document}
\long\def\opcenter#1{\vfill\smash{\minibox{#1}}}
\begin{frame}
\begin{overprint}
\onslide<1>
\opcenter{A short paragraph}
\onslide<2>
\opcenter{A\\
longer\\
paragraph\\
with\\
a\\
few\\
lines}

% This frame uses minipage instead of minibox. minibox
% does not accept a block as its argument.
\onslide<3>
\vfill\smash{\begin{minipage}[c]{1.0\linewidth}
\begin{block}{Title}
A block \\
with\\
a\\
few lines
\end{block}
\end{minipage}}\vfill
\end{overprint}
\end{frame}
\end{document}

-
That's fine, except it doesn't accept a block as argument. I'm updating the question. –  Jellby Mar 14 '14 at 15:26
@Jellby See my updated answer for the third frame. You can use minipage as well if you do not mind specifying the width. Now you can update the macro to your taste. –  Masroor Mar 14 '14 at 15:37
I'm sorry, I think I have to add new "requirements" :D See the updated question, I need it to work with paragraphs, and listings support would be welcome. –  Jellby Mar 14 '14 at 16:02