Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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).

share|improve this question

1 Answer 1

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}
share|improve this answer
    
That's fine, except it doesn't accept a block as argument. I'm updating the question. –  Jellby Mar 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 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 at 16:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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