# Changing the properties of an edge on a later slide [duplicate]

I am using beamer and TikZ and would like to change the color and thickness of an edge in the second slide of the same frame. Here is what I tried:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{shapes,shapes.geometric,arrows,fit,calc,positioning,automata}

\begin{document}

\frame{
\newcommand*\properties{}
\only<2>{\renewcommand*{\properties}{orange, ultra thick}}
\begin{figure}
\begin{tikzpicture}[node distance = 1.5cm, scale=0.8]

\node (1) {1};
\node[right = of 1] (2) {2};

\path[->]
(1) edge[\properties] (2);

\end{tikzpicture}
\end{figure}
}

\end{document}


The strange thing is that when I put only orange or only ultra thick in the definition of \properties, everything works as expected. In addition, if I just put orange, ultra thick together in the bracket that follows edge, it is still fine (and of course in this case the edge has the same look on both slides). But when I have both of them there, an error occurs:

Package pgfkeys Error: I do not know the key '/tikz/orange, ultra thick' and I am going to ignore it. Perhaps you misspelled it.

May I know why this is the case? How should I correct it to achieve the desired result (i.e., the edge turning both orange and thicker on the second slide)? Thank you!

• – Ignasi Apr 11 '16 at 20:51

I don't think that you can put an \only... command inside the edge command like this. Rather, you have to apply \only... to a full command.

The following works:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{shapes,shapes.geometric,arrows,fit,calc,positioning,automata}

\tikzset{properties/.style={orange, ultra thick}}
\begin{document}

\frame{
\begin{figure}
\begin{tikzpicture}[node distance = 1.5cm, scale=0.8]

\node (1) {1};
\node[right = of 1] (2) {2};

\only<2>{\path[->](1) edge[properties] (2);}
\only<1,3->{\path[->](1) edge (2);}

\end{tikzpicture}
\end{figure}
}

\end{document}


I have used \tikzset to define your properties in the "tikz way". If you are only using this in one tikzpicture environment you can also define this "locally" by

\begin{tikzpicture}[node distance = 1.5cm, scale=0.8,
properties/.style={orange, ultra thick}]
...
\end{tikzpicture}


Edit I

As pointed out in How to modify a node in TikZ when using beamer's overlays, another way of doing this to use \only... to set the properties by writing:

\only<1,3->{\tikzset{properties/.style={}}}
\only<2>{\tikzset{properties/.style={orange, ultra thick}}}


Now your tikzpicture environment is no longer requires any \only... statements and for the node you just write:

\path[->](1) edge[properties] (2);


Edit II

Note that anything inside \only is local to the frame. You could instead, for example, make

\tikzset{properties/.style={orange, ultra thick}}


a "global" definition at the in your preamble and then use

\only<1,3->{\tikzset{properties/.style={}}}


whenever you want to turn this definition "off". Note also that any \tikzset inside a frame applies only for that frame and will not be accessible in other frames, so this needs to go into the preamble or, more accurately, outside a frame.

• Thanks! Is the method in your Edit also a local definition? So that I won't have the properties style in other frames? – Fang Jing Apr 11 '16 at 23:02
• Yes, it's local. See Edit II. – Andrew Apr 12 '16 at 7:32
• Thank you a lot! I think you missed a } at the end of \tikzset{properties/.style={orange, ultra thick}} in Edit II. – Fang Jing Apr 12 '16 at 18:15