我想在 beamer 中以以下方式显示问题和答案:
\documentclass{beamer}
\begin{document}
\begin{frame}[t]{Equations}
Solve the equation
\begin{enumerate}
\only<1-2>{\item[1.] $x+1=0$ \\}
\only<2> {Answer: $x = -1$}
\only<3-4>{\item[2.] $x+3=0$ \\}
\only<4> {Answer: $x = -3$}
\end{enumerate}
\end{frame}
\end{document}
重要的是,我想要:
- 每张幻灯片只有一个问题
- 让答案出现在问题之后,而不出现新的 \item
- 项目不共享空间,即每个项目都出现在其幻灯片的顶部
我找不到一种方法来实现上述功能,同时保持枚举计数器自动运行,因此上例中使用了硬编码计数器。有没有一种简单的方法来实现这一点?
答案1
这是一个建议。
您可以为问题以及问答叠加层创建自定义计数器。其余部分非常简单:初始化计数器(\newcounter{}
)、设置计数器(\setcounter{}
)和递增(\stepcounter{}
或\addtocounter{}
)。
% arara: lwpdflatex
\documentclass{beamer}
% Question counter
\newcounter{question}
% Question overlay counter
\newcounter{questionoverlay}
% Answer overlay counter
\newcounter{answeroverlay}
% Command that automatically increases counters in order to have
% Automatic question number in \item (including increments)
% Automatic overlay handling (including increments
\newcommand{\questionanswer}[2]{%
\only<\value{questionoverlay}-\value{answeroverlay}>{\item[\arabic{question}.] #1 \\}%
\only<\value{answeroverlay}>{Answer : #2}%
\stepcounter{question}%
\addtocounter{questionoverlay}{2}%
\addtocounter{answeroverlay}{2}%
}
% Environment used to reset the counters with an optional starting number for the question counter
\newenvironment{myenumerate}[1][1]{%
\setcounter{question}{#1}%
\setcounter{questionoverlay}{1}%
\setcounter{answeroverlay}{2}%
\begin{enumerate}%
}{%
\end{enumerate}%
}
\begin{document}
\begin{frame}[t]{Equations}
Solve the equation
\begin{myenumerate}
\questionanswer{$x+1=0$}{$x = -1$}
\questionanswer{$x+3=0$}{$x = -3$}
\end{myenumerate}
\end{frame}
\begin{frame}[t]{Equations}
Solve the equation
\begin{myenumerate}[10]
\questionanswer{$x+1=0$}{$x = -1$}
\questionanswer{$x+3=0$}{$x = -3$}
\end{myenumerate}
\end{frame}
\end{document}