Acione automaticamente comandos de formatação agrupados em sobreposições

Acione automaticamente comandos de formatação agrupados em sobreposições

Gostaria de uma saída idêntica à seguinte:

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

No entanto, em vez de \alt<5>{{\color{blue}on average}}{on average}, quero colocar preguiçosamente \groupA{on average}nas duas primeiras instâncias "em média" e na terceira e última algo como \revealGroupA{on average}. Ou seja, quero escrever o seguinte código, mas obter a mesma saída acima:

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

Algumas notas:

  • No exemplo, o argumento ("em média") é sempre o mesmo, mas em outros casos de uso esse não é o caso.

  • Eu também faço muito isso em matemática, então seria bom que o comando funcionasse em matemática e fora dela.

  • Eu provavelmente usaria esse mecanismo em vários quadros diferentes do mesmo arquivo.

  • Não tenho certeza se é relevante, mas pretendo estender a resposta para criar também um \groupBcomando, que faria essencialmente a mesma coisa, mas usaria uma cor diferente. A razão para isso é que talvez eu queira usar ambos \groupAe \groupBno mesmo quadro.

Responder1

Você poderia usar o totcountpacote para armazenar o número de sobreposição no qual seu grupo será revelado entre compilações (não reutilize o mesmo grupo em frames diferentes):

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

insira a descrição da imagem aqui

informação relacionada