2

I want to use beamer overlays to change the color of equations in an align environment.

On each slide, I want all equations to be black, except one which should be red. On the first slide, the first equation should be red, on the second slide, the second equation should be red, etc.

\documentclass{beamer}
\usepackage{amsmath, bm}

\begin{document}

\begin{frame}
\begin{align*}
\bm{f_t} &= \sigma(\bm{W_f} \cdot [\bm{h_{t-1}}, \bm{x_t}] + \bm{b_f}) \\
\bm{i_t} &= \sigma(\bm{W_i} \cdot [\bm{h_{t-1}}, \bm{x_t}] + \bm{b_i}) \\
\bm{\tilde{C}_t} &= \tanh(\bm{W_{\tilde{C}}} \cdot [\bm{h_{t-1}}, \bm{x_t}] + \bm{b_{\tilde{C}}}) \\
\bm{C_t} &= \bm{f_t} \odot \bm{C_{t-1}} + \bm{i_t} \odot\bm{\tilde{C}_t} \\
\bm{o_t} &= \sigma(\bm{W_o} \cdot [\bm{h_{t-1}}, \bm{x_t}] + \bm{b_o}) \\
\bm{h_t} &= \bm{o_t} \odot \tanh(\bm{C_t})
\end{align*}
\end{frame}

\end{document}

If anybody can help me, I'd be incredibly thankful. I've been fiddling with \onslide for hours!

2
  • 1
    Do the equations have to appear after each other or is it enough that the color changes? – campa Apr 4 '19 at 16:09
  • Preferably the equations would appear one after each other. Sorry, I should have mentioned that in the question. – Henry Apr 4 '19 at 16:45
4

You can use \alert to highlight each line after another:

\documentclass{beamer}
\usepackage{amsmath, bm}

\begin{document}

\begin{frame}
\begin{align*}
\alert<+>{\bm{f_t}} & \alert<.>{=\sigma(\bm{W_f} \cdot [\bm{h_{t-1}}, \bm{x_t}] + \bm{b_f})} \\
\alert<+>{\bm{i_t}} &\alert<.>{= \sigma(\bm{W_i} \cdot [\bm{h_{t-1}}, \bm{x_t}] + \bm{b_i})} \\
\alert<+>{\bm{\tilde{C}_t}} &\alert<.>{= \tanh(\bm{W_{\tilde{C}}} \cdot [\bm{h_{t-1}}, \bm{x_t}] + \bm{b_{\tilde{C}}})} \\
\alert<+>{\bm{C_t}} &\alert<.>{= \bm{f_t} \odot \bm{C_{t-1}} + \bm{i_t} \odot\bm{\tilde{C}_t}} \\
\alert<+>{\bm{o_t}} &\alert<.>{= \sigma(\bm{W_o} \cdot [\bm{h_{t-1}}, \bm{x_t}] + \bm{b_o})} \\
\alert<+>{\bm{h_t}} &\alert<.>{= \bm{o_t} \odot \tanh(\bm{C_t})}
\end{align*}
\end{frame}

\end{document}

enter image description here

2
  • Thanks so much sam! Although is it possible for the equations to appear one after each other as well? – Henry Apr 4 '19 at 16:42
  • 1
    @Henry Sure it is possible, although in your question you explicitly asked that all equations to be black, only one red. Try \uncover<+->{\alert<.>{\bm{i_t}}} &\uncover<.->{\alert<.>{= \sigma(\bm{W_i} \cdot [\bm{h_{t-1}}, \bm{x_t}] + \bm{b_i})}} \\ – samcarter_is_at_topanswers.xyz Apr 4 '19 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.