这个问题是答案的后续这里。我希望一个叠加层上的命令能够“触发”框架内先前叠加层上的文本格式。我在这里询问的扩展是如何拥有一个可以跨框架重复使用的命令。
下面是一个使用参考答案中的机制的示例,但该机制预计依赖于仅在一个框架上使用的命令。第二帧的输出符合预期,但由于此限制,第一帧的输出并不理想。
我希望命令\docolorOnAA
和\dotriggerAA
每个命令只接受一个参数(目前就是这种情况)。也就是说,我不想另外传递计数器名称或标签作为参数。
编辑:我将使用它的文档是我的讲义,它将有 900 帧,并且我将在相当一部分帧(~20%)中使用提供的命令,因此希望有一个可以很好地扩展到大型文档的机制。
编辑:我想用它pdflatex
来编译文档。
\documentclass{beamer}
\newcommand{\omcolorA}[1]{\textcolor{teal} {#1}}
\newcommand{\omcolorB}[1]{\textcolor{purple} {#1}}
% https://tex.stackexchange.com/a/679551/12212
\makeatletter
\newcommand*{\slideinframe}{\beamer@slideinframe}
\makeatother
\usepackage{totcount}
\newcounter{overlaycolorOnAA}
\setcounter{overlaycolorOnAA}{0}
\newcounter{overlaycolorOnBB}
\setcounter{overlaycolorOnBB}{0}
\newcommand{\dotriggerAA}[1]{%
\only<.>{\setcounter{overlaycolorOnAA}{\slideinframe}}%
\alt<.>{\omcolorA{#1}}{#1}%
}
\newcommand{\dotriggerBB}[1]{%
\only<.>{\setcounter{overlaycolorOnBB}{\slideinframe}}%
\alt<.>{\omcolorB{#1}}{#1}%
}
\newcommand{\docolorOnAA}[1]{%
\alt<\totvalue{overlaycolorOnAA}>{\omcolorA{#1}}{#1}%
}
\newcommand{\docolorOnBB}[1]{%
\alt<\totvalue{overlaycolorOnBB}>{\omcolorB{#1}}{#1}%
}
\regtotcounter{overlaycolorOnAA}
\regtotcounter{overlaycolorOnBB}
\begin{document}
\begin{frame}[<+->]{Sampling}
\begin{itemize}
\item A random sample of ten people from the US will \docolorOnAA{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, \docolorOnAA{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 ``\dotriggerAA{on average}'' mean above?
\item It means that if we were to take a lot of samples.... blah blah.
\end{itemize}
\end{frame}
\begin{frame}[<+->]{Sampling}
\begin{itemize}
\item A random sample of ten people from the US will \docolorOnAA{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, \docolorOnAA{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 misc
\item misc
\item ...
\item What does ``\dotriggerAA{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}
答案1
您可以将想要显示组的幻灯片编号写入.aux 文件,并在第二次编译时检索它。
在以下示例中,我定义了三个可以使用的组(例如\groupA
,,)。如果您需要更多,请将行中的替换 \groupB
为所需的组数(不要使用大于 26 的数字)。\groupC
3
\loop\ifnum\value{MaxRevealGroup} < 3
\documentclass{beamer}
\makeatletter
\newcommand*\newreveal{\@newl@bel{revealgroup}}
\newcounter{MaxRevealGroup}
\newcommand*\NewRevealGroup[1]{
\expandafter\newcommand\csname revealGroup#1\endcsname[1]{%
\only<.>{\immediate\write\@auxout{%
\string\newreveal{Group#1-Frame\theframenumber}{\the\beamer@slideinframe}}}%
\alert<.>{##1}%
}
\expandafter\newcommand\csname group#1\endcsname[1]{%
\ifcsname revealgroup@Group#1-Frame\theframenumber\endcsname
\alert<\csname revealgroup@Group#1-Frame\theframenumber\endcsname>{##1}%
\else
##1%
\fi
}
}
\loop\ifnum\value{MaxRevealGroup} < 3
\stepcounter{MaxRevealGroup}
\expandafter\NewRevealGroup\expandafter{\expanded{\Alph{MaxRevealGroup}}}
\repeat
\makeatother
\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}
\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 It means that if we were to take a lot of samples.... blah blah.
\item What does ``\revealGroupA{on average}'' mean above?
\end{itemize}
\end{frame}
\begin{frame}[<+->]{Sampling}
\begin{itemize}
\item A random sample of ten people from the US will \groupB{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, \groupB{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 ``\revealGroupB{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}
编辑
使用以下代码,每个组都显示不同的颜色。颜色在\RrvealGroupColorsList
序言开头的列表中指定(定义的组数是列表中的颜色数)。
\documentclass{beamer}
\newcommand*\RrvealGroupColorsList{teal,purple,orange}
\makeatletter
\newcommand*\newreveal{\@newl@bel{revealgroup}}
\newcommand*\NewRevealGroup[2]{
\expandafter\newcommand\csname revealGroup#1\endcsname[1]{%
\only<.>{\immediate\write\@auxout{%
\string\newreveal{Group#1-Frame\theframenumber}{\the\beamer@slideinframe}}}%
\alt<.>{\textcolor{#2}{##1}}{##1}%
}
\expandafter\newcommand\csname group#1\endcsname[1]{%
\@ifundefined{revealgroup@Group#1-Frame\theframenumber}{%
##1%
}{%
\alt<\csname revealgroup@Group#1-Frame\theframenumber\endcsname>{\textcolor{#2}{##1}}{##1}%
}%
}
}
\newcounter{RevealGroup}
\@for\group@color:=\RrvealGroupColorsList\do{
\stepcounter{RevealGroup}
\@expandtwoargs\NewRevealGroup{\Alph{RevealGroup}}{\group@color}
}
\makeatother
\begin{document}
\begin{frame}[<+->]{Sampling}
\begin{itemize}
\item A random sample of ten \groupB{people} from the US will \groupA{on average} \groupC{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 \revealGroupC{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? \revealGroupB{blah blah}.
\item It means that if we were to take a lot of samples....
\end{itemize}
\end{frame}
\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 It means that if we were to take a lot of samples.... blah blah.
\item What does ``\revealGroupA{on average}'' mean above?
\end{itemize}
\end{frame}
\end{document}
答案2
这里采用一种半手动方法,其中包括计数器名称中的帧号。
您必须手动维护使用该功能的框架列表,在评论下% list all frames here on which you use the overlay groups
\documentclass{beamer}
\usepackage{totcount}
\newcommand{\revealGroupA}[1]{%
\only<1>{
\newcounter{overlaygroupA-\insertframenumber}
\setcounter{overlaygroupA-\insertframenumber}{0}
}
\only<.>{\setcounter{overlaygroupA-\insertframenumber}{\insertslidenumber}}%
\alert<.>{#1}%
}
\newcommand{\groupA}[1]{%
\alert<\totvalue{overlaygroupA-\insertframenumber}>{#1}%
}
% list all frames here on which you use the overlay groups
\regtotcounter{overlaygroupA-1}
\regtotcounter{overlaygroupA-2}
\begin{document}
\begin{frame}[<+->]
\frametitle{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}
\begin{frame}[<+->]
\frametitle{Next Frame}
\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 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}