38

For making a small quiz in class I am working on a presentation in beamer.

I want to change the color of statements to red (wrong statement) or green (right statement) but only after my class answered the question.

I was searching the internet, but only found the color package, where you apparently can only change the text color before it appears.

Can someone point me into the right direction?

0

2 Answers 2

42

beamer provides an overlay specification with most of its macros/environments. It allows you to say (for example) ...\alert<2>{<stuff>}... so that <stuff> prints normally on slides other than number 2. \color itself is overlay aware in the form \color<2->{blue}{<stuff>} that would print <stuff> in blue from slide 2 onward. Alternatively, one can use something like ...{\only<2>{\color{blue}}<stuff>}... which prints <stuff> in blue only on slide 2.

Here's a short example

enter image description here

\documentclass{beamer}% http://ctan.org/pkg/beamer
\begin{document}
\begin{frame}
Some text {\only<2>{\color{blue}}and stuff}.
\end{frame}
\end{document}

Note that beamer already loads xcolor.

4
  • This is exactly what I need, with one little modification: I want the blue stuff be shown after, say, slide 2.
    – marktani
    Nov 1, 2012 at 21:34
  • 2
    I found it on the documentation page you linked, I will have to write \only<2-> and so on. Thanks! :)
    – marktani
    Nov 1, 2012 at 21:36
  • \color also affects the text after "and stuff", so if you do not want the rest of the line to turn blue, make sure you use {\color<2->{blue}{and stuff}} and more stuff instead of \color<2->{blue}{and stuff} and more stuff. Dec 10, 2020 at 13:00
  • @AnthonyLabarre: Correct. That's what I used. The grouping limits the scope of \color. Alternatively, since \color is overlay-aware, you can use {\color<2>{blue}and stuff}.
    – Werner
    Dec 10, 2020 at 18:05
5

I searched for the difinition of alert command, and found these:

% beamercolorthemedefault.sty
\setbeamercolor{alerted text}{fg=blue}
% beamerfontthemedefault.sty
\setbeamerfont{alerted text}{}
% beamerbasearticle.sty
\defbeamertemplate<article>*{alerted text begin}{default}{\ifmmode\else\begin{itshape}\fi}
\defbeamertemplate<article>*{alerted text end}{default}{\ifmmode\else\end{itshape}\fi}
% beamerbaselocalstructure.sty
\newenvironment{alertenv}{\begin{altenv}%
    {\usebeamertemplate{alerted text begin}\usebeamercolor[fg]{alerted text}\usebeamerfont{alerted text}}
    {\usebeamertemplate{alerted text end}}{\color{.}}{}}{\end{altenv}}
\newcommand<>{\alert}[1]{\begin{alertenv}#2\relax#1\end{alertenv}}

Simillary I define rightstate and wrongstate commands that can be used like alert command.

\documentclass{beamer}

\setbeamercolor{rightstateed text}{fg=green}
\setbeamerfont{rightstateed text}{}
\defbeamertemplate<article>*{rightstateed text begin}{default}{\ifmmode\else\begin{itshape}\fi}
\defbeamertemplate<article>*{rightstateed text end}{default}{\ifmmode\else\end{itshape}\fi}
\newenvironment{rightstateenv}{\begin{altenv}%
    {\usebeamertemplate{rightstateed text begin}\usebeamercolor[fg]{rightstateed text}\usebeamerfont{rightstateed text}}
    {\usebeamertemplate{rightstateed text end}}{\color{.}}{}}{\end{altenv}}
\newcommand<>{\rightstate}[1]{\begin{rightstateenv}#2\relax#1\end{rightstateenv}}

\setbeamercolor{wrongstateed text}{fg=red}
\setbeamerfont{wrongstateed text}{}
\defbeamertemplate<article>*{wrongstateed text begin}{default}{\ifmmode\else\begin{itshape}\fi}
\defbeamertemplate<article>*{wrongstateed text end}{default}{\ifmmode\else\end{itshape}\fi}
\newenvironment{wrongstateenv}{\begin{altenv}%
    {\usebeamertemplate{wrongstateed text begin}\usebeamercolor[fg]{wrongstateed text}\usebeamerfont{wrongstateed text}}
    {\usebeamertemplate{wrongstateed text end}}{\color{.}}{}}{\end{altenv}}
\newcommand<>{\wrongstate}[1]{\begin{wrongstateenv}#2\relax#1\end{wrongstateenv}}

\begin{document}
\begin{frame}
    \begin{itemize}
    \item \wrongstate<2>{wrong statement}
    \item \rightstate<3>{right statement}
    \end{itemize}
\end{frame}
\end{document}

Here's the result:

You must log in to answer this question.

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