自动触发覆盖中的分组格式化命令

自动触发覆盖中的分组格式化命令

我想要的输出与以下内容相同:

\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}

在此处输入图片描述

相关内容