Beamer - 編寫巨集以僅發現框架中列舉的項目 i

Beamer - 編寫巨集以僅發現框架中列舉的項目 i

我想在演講中的多個位置重複某個框架。然而,每次我都希望所有項目都被揭開,或者只有項目 i 被揭開。如何定義一個宏,它能夠產生一個框架,其中包含所有未覆蓋的項目或僅我未覆蓋的項目?


例子

以下程式碼產生 4 張幻燈片。

  1. 所有物品均未發現
  2. 僅第 3 項未覆蓋
  3. 僅第 1 項未覆蓋
  4. 僅第 2 項未覆蓋

代碼:

\documentclass{beamer}

\setbeamercovered{transparent}

\begin{document}

\begin{frame}{Repeating frame}
\begin{enumerate}
\item \uncover<1>{The is item 1}
\item \uncover<1>{The is item 2}
\item \uncover<1>{The is item 3}
\end{enumerate}
\end{frame}

\begin{frame}{Repeating frame}
\begin{enumerate}
\item \uncover<0>{The is item 1}
\item \uncover<0>{The is item 2}
\item \uncover<1>{The is item 3}
\end{enumerate}
\end{frame}

\begin{frame}{Repeating frame}
\begin{enumerate}
\item \uncover<1>{The is item 1}
\item \uncover<0>{The is item 2}
\item \uncover<0>{The is item 3}
\end{enumerate}
\end{frame}

\begin{frame}{Repeating frame}
\begin{enumerate}
\item \uncover<0>{The is item 1}
\item \uncover<1>{The is item 2}
\item \uncover<0>{The is item 3}
\end{enumerate}
\end{frame}

\end{document}

我想使用以下更簡潔的程式碼來產生相同的輸出:

\repeatingframe{0}
\repeatingframe{3}
\repeatingframe{1}
\repeatingframe{2}

如何定義巨集\repeatingframe才能實現此目的?

答案1

我不會定義一個新命令,而是使用它本身\againframe提供的功能beamer

\documentclass{beamer}

\setbeamercovered{transparent}

\begin{document}

  \begin{frame}<4>[label=repeater]{Repeating frame}
    \begin{enumerate}
      \item \uncover<1,4>{The is item 1}
      \item \uncover<2,4>{The is item 2}
      \item \uncover<3-4>{The is item 3}
    \end{enumerate}
  \end{frame}

  \againframe<1>{repeater}
  \againframe<2>{repeater}
  \againframe<3>{repeater}

\end{document}

重複具有變化的轉發器幀

如果這是一次性的並且您確實想使用特定命令來重複此特定幀,您可以嘗試:

\documentclass{beamer}

\setbeamercovered{transparent}

\newcommand<>{\repeatingframe}{%
  \againframe#1{repeater}}

\begin{document}

  \begin{frame}<4>[label=repeater]{Repeating frame}
    \begin{enumerate}
      \item \uncover<1,4>{The is item 1}
      \item \uncover<2,4>{The is item 2}
      \item \uncover<3-4>{The is item 3}
    \end{enumerate}
  \end{frame}

  \repeatingframe<1>
  \repeatingframe<2>
  \repeatingframe<3>

\end{document}

這會產生相同的輸出,但靈活性稍差。

\newcommand<>{\repeatingframe}[1]{%
  \againframe#2{#1}}

會讓你寫

\repeatingframe<1>{repeater}

這樣您就可以對不同的框架使用具有不同標籤的相同命令,即相似的語法(只需多一個參數),但靈活性更高。不過,\againframe在這種情況下您也可以使用。

答案2

這是透過簡單的\ifnum #1=xx ... \else ... \fi條件檢查的一種可能的解決方案。

在此輸入影像描述 在此輸入影像描述 在此輸入影像描述 在此輸入影像描述

程式碼

\documentclass{beamer}

\setbeamercovered{transparent}

\newcommand{\repeatingframe}[1]{
\ifnum #1=0   
\def\a{1} \def\b{1} \def\c{1}
\else \ifnum #1=3
\def\a{0} \def\b{0} \def\c{1}
\else \ifnum #1=1
\def\a{1} \def\b{0} \def\c{0}
\else \ifnum #1=2
\def\a{0} \def\b{1} \def\c{0}
\fi
\fi
\fi
\fi
\begin{frame}{Repeating frame}
\begin{enumerate}
\item \uncover<\a>{The is item 1}
\item \uncover<\b>{The is item 2}
\item \uncover<\c>{The is item 3}
\end{enumerate}
\end{frame}
}

\begin{document}

\repeatingframe{0}
\repeatingframe{3}
\repeatingframe{1}
\repeatingframe{2}

\end{document}

答案3

這是一種更通用的方法,您還可以確定項目的總數並為單一框架提供替代標題:

\documentclass{beamer}
\setbeamercovered{transparent}

\usepackage{pgffor}

\makeatletter
\@namedef{theitem1}{The is item 1}
\@namedef{theitem2}{The is item 2}
\@namedef{theitem3}{The is item 3}
\@namedef{theitem4}{The is item 4}
\@namedef{theitem5}{The is item 5}
\@namedef{theitem6}{The is item 6}
\@namedef{theitem7}{The is item 7}
\newcount\uncovered
\newcount\uncovermax
\newcommand{\repeatingframe}[3][Repeating frame]{%
  \uncovermax#3
  \begin{frame}{#1}
  \begin{enumerate}
    \itemprocess{#2}
  \end{enumerate}
  \end{frame}
}
\newcommand{\itemprocess}[1]{%
  \begingroup
  \uncovered#1
  \ifnum\uncovered=0
    \foreach \n in {1,...,\the\uncovermax}{%
      \item \uncover<1>{\csname theitem\n\endcsname}}
  \else
    \ifnum\uncovered>1
      {\advance\uncovered by -1
      \foreach \n in {1,...,\the\uncovered}{%
        \item \uncover<0>{\csname theitem\n\endcsname}}}
    \fi
    \item \uncover<1>{\csname theitem\the\uncovered\endcsname}
    \ifnum\uncovered<\uncovermax
      {\advance\uncovered by 1
      \foreach \n in {\the\uncovered,...,\the\uncovermax}{%
        \item \uncover<0>{\csname theitem\n\endcsname}}}
    \fi
  \fi
  \endgroup}%
\makeatother

\begin{document}

\repeatingframe{0}{3}
\repeatingframe{3}{3}
\repeatingframe{1}{3}
\repeatingframe{2}{3}

%for testing the generalized version
%\repeatingframe[Repeating frame with different title]{1}{7}
%\repeatingframe{2}{7}
%\repeatingframe{3}{7}
%\repeatingframe{4}{7}
%\repeatingframe{5}{7}
%\repeatingframe{6}{7}
%\repeatingframe{7}{7}

\end{document}

輸出

相關內容