How can I apply a style to existing tikz node on specific slides

I don't think you can do this the way you want to (assuming I understand the question correctly), because once a node is drawn, there's no way to change its appearance. I'd suggest using Beamer's \alt macro:

\alt<2>{\node[module,selected] at (nodeA) {node A};}{\node[module] at (nodeA) {node A};}
\alt<3>{\node[module,selected] at (nodeB) {node B};}{\node[module] at (nodeB) {node B};}
\node[comment,text width=6cm,right=0.25 of nodeA]{\alt<2>{short description}{long description}};
\node[comment,text width=6cm,right=0.25 of nodeB]{\alt<3>{short description}{long description}};

Or something like that (you might have to tinker with the semicolons to get it to work, I can't test that at the moment).

Another option would be to actually just draw a new node. If you include

\node[module,selected] at (nodeA) {node A};

inside \only<2>, that will draw a node that looks just like node A, except with a red background, at the same position at node A. The new node will cover up the original node A.


Sometimes, to avoid repetitions, it may be nice to do something like this:

% #1    Overlay specs.
% #2    Style name.
% #4    Style properties.
\def\onlystyle<#1>#2#3{%
    \alt<#1>{%
        \tikzset{#2/.style = {#3}}
    }{%
        \tikzset{#2/.style = {}}
    }%
}

Then, if you put, for example, this within a frame:

\onlystyle<2>{selected}{fill = red}

the style selected will be defined as fill = red on the second slide of the animation, and as a style with no effect whatsoever on every other slide. Then, you can write a readable figure such as:

\begin{tikzpicture}
    \node           at (0, 0) {A};
    \node[selected] at (1, 0) {B};
    \node           at (2, 0) {C};
\end{tikzpicture}

and the “B” node will be highlighted on the second slide. This way, you don't have to copy-paste tons of node definitions. Of course, it cannot be applied to every single animation need, but I like to keep this technique up my sleeve.

Tags:

Latex

Beamer

Tikz