自動觸發疊加中的分組格式化指令

自動觸發疊加中的分組格式化指令

我希望輸出與以下內容相同:

\documentclass{beamer}
\begin{document}

\begin{frame}[<+->]{Sampling}
\begin{itemize}
\item A random sample of ten people from the US will \alt<5>{{\color{blue}on average}}{on average} produce
five men and five women, but... \uncover<+->{ any given trial is likely to over-represent one sex and underrepresent
the other.}
\item Analogy: if you flip a fair coin 10 times, \alt<5>{{\color{blue}on average}}{on average} you'll get 5
heads and 5 tails, but... \uncover<+->{ sometimes we might get 7 heads and 3 tails, and other times 8 tails
and 2 heads.}
\item What does ``\alt<5>{{\color{blue}on average}}{on average}'' mean above?
\item It means that if we were to take a lot of samples.... blah blah.
\end{itemize}
\end{frame}

\end{document}

然而,\alt<5>{{\color{blue}on average}}{on average}我不想懶惰地放置\groupA{on average}「平均」的前兩個實例,而在第三個和最後一個實例上放置類似的東西\revealGroupA{on average}。也就是說,我想編寫以下程式碼但獲得與上面相同的輸出:

\documentclass{beamer}
\begin{document}

\begin{frame}[<+->]{Sampling}
\begin{itemize}
\item A random sample of ten people from the US will \groupA{on average} produce
five men and five women, but... \uncover<+->{ any given trial is likely to over-represent one sex and underrepresent
the other.}
\item Analogy: if you flip a fair coin 10 times, \groupA{on average} you'll get 5
heads and 5 tails, but... \uncover<+->{ sometimes we might get 7 heads and 3 tails, and other times 8 tails
and 2 heads.}
\item What does ``\revealGroupA{on average}'' mean above?
\item It means that if we were to take a lot of samples.... blah blah.
\end{itemize}
\end{frame}

\end{document}

一些注意事項:

  • 在範例中,參數(“平均”)始終相同,但在其他用例中並非如此。

  • 我在數學中也經常這樣做,因此該命令在數學及其之外工作會很好。

  • 我可能會在同一文件的幾個不同框架中使用這種機制。

  • 不確定是否相關,但我計劃擴展答案以創建一個\groupB命令,該命令本質上會執行相同的操作但使用不同的顏色。這樣做的原因是我可能想在同一框架中使用\groupA和。\groupB

答案1

您可以使用該totcount套件來儲存在編譯之間應顯示您的群組的覆蓋編號(不要在不同幀上重複使用同一組):

\documentclass{beamer}


\makeatletter
\newcommand*{\slideinframe}{\beamer@slideinframe}
\makeatother

\usepackage{totcount}


\setbeamercolor{alerted text}{fg=blue}

\newcounter{overlaygroupA}
\setcounter{overlaygroupA}{0}

\newcommand{\revealGroupA}[1]{%
  \only<.>{\setcounter{overlaygroupA}{\slideinframe}}%
  \alert<.>{#1}%
}

\newcommand{\groupA}[1]{%
  \alert<\totvalue{overlaygroupA}>{#1}%
}

\regtotcounter{overlaygroupA}

\begin{document}

\begin{frame}[<+->]{Sampling}
\begin{itemize}
\item A random sample of ten people from the US will \groupA{on average} produce
five men and five women, but... \uncover<+->{ any given trial is likely to over-represent one sex and underrepresent
the other.}
\item Analogy: if you flip a fair coin 10 times, \groupA{on average} you'll get 5
heads and 5 tails, but... \uncover<+->{ sometimes we might get 7 heads and 3 tails, and other times 8 tails
and 2 heads.}
\item What does ``\revealGroupA{on average}'' mean above?
\item It means that if we were to take a lot of samples.... blah blah.
\end{itemize}

\end{frame}

\end{document}

在此輸入影像描述

相關內容