
是否有一種「簡單」的方法可以將環境中的東西垂直居中overprint
?
根據當前的答案,這是我的測試文檔
\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}
現在的問題是段落分隔符號(替代\smash
?)和逐字內容(listings
)。
答案1
想法是使用\smash
隱藏文字的高度,使用\vfill
s 垂直居中,然後使用minibox
在文字中換行。
您也可以使用minipage
代替minibox
,但前者需要指定寬度。
\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}