我使用下面的代码来突出显示我正在谈论的地方。
\newcommand<>{\hl}[1]{{
\alt#2{\colorbox{yellow}{#1}}{#1}
}}
\onslide<1->{\hl<1>{when they comeout will in a yellow background color\\}}
\onslide<2->{\hl<2>{when they comeout will in a yellow background color\\}}
\onslide<3->{\hl<3>{when they comeout will in a yellow background color\\}}
\onslide<4->{\hl<4>{when they comeout will in a yellow background color}}
我认为它可以通过一个新命令来简化。
为了整合命令,我尝试了下面的代码:
\newcommand<>{\next}[1]{
\onslide#2-{\alt#2{\colorbox{yellow}{#1}}{#1}}
}
但效果不太好。
那么,如何将这些命令整合为一个命令?
答案1
您可以使用\temporal
宏代替\alt
,它允许您定义幻灯片前、幻灯片上和幻灯片后的替代方案:
\temporal<⟨overlay specification⟩>{⟨before slide text⟩}{⟨default text⟩}{⟨after slide text⟩}
\documentclass{beamer}
\newcommand<>{\hl}[1]{{
\temporal#2{}{\colorbox{yellow}{#1}}{#1}
}}
\begin{document}
\begin{frame}
\hl<1>{when they comeout will in a yellow background color}
\hl<2>{when they comeout will in a yellow background color}
\hl<3>{when they comeout will in a yellow background color}
\hl<4>{when they comeout will in a yellow background color}
\end{frame}
\end{document}
(略有不同的示例 + 动画)
% https://tex.stackexchange.com/questions/577337
\documentclass{beamer}
% \temporal<⟨overlay specification⟩>{⟨before slide text⟩}{⟨default text⟩}{⟨after slide text⟩}
\newcommand<>{\myOwnCommand}[1]{{
\temporal#2{}{\colorbox{yellow}{#1}}{#1}
}}
\begin{document}
\begin{frame}
\frametitle{Frame Title}
\begin{itemize}[<+->]
\item \myOwnCommand<1>{when they come out will be in a yellow background color}
\item \myOwnCommand<2>{when they come out will be in a yellow background color}
\item \myOwnCommand<3>{when they come out will be in a yellow background color}
\end{itemize}
\end{frame}
\end{document}