1

I want to display questions and answers in the following way in 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}

Importantly, I want:

  • to have only one question per slide
  • to have the answer appear after the question, without a new \item
  • the items not to share space, ie that each item appears at the top of its slide

I can't find a way to have the above while keeping the enumerate counter running automatically, hence the hard-coded counters in the example above. Is there a simple way to have that as well?

1 Answer 1

1

Here is a proposal.

You can create custom counters for questions, and for the question and answer overlays. The rest is pretty straightforward : initialize the counters (\newcounter{}), set the counters (\setcounter{}), and increment (\stepcounter{} or \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}

enter image description here enter image description here enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .