TikZ: redefine/update node label

Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I need to draw many nodes with labels that I can calculate from their indices. However, a small amount of them do not follow the rule, thus I need to assign their labels manually. Can I do that somehow?
MWE:
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,30
node at (i,0) [rectangle,label=above:i] (vi) $i$;
% here I want to make the label of node v7 to become $varnothing$
endtikzpicture
enddocument
Note: this has nothing to do with animation, I just want to create the nodes in a loop and then change labels for some of them.
UPD: I corrected MWE, as the original one was not exactly what I implied.
tikz-pgf tikz-node
add a comment |Â
up vote
5
down vote
favorite
I need to draw many nodes with labels that I can calculate from their indices. However, a small amount of them do not follow the rule, thus I need to assign their labels manually. Can I do that somehow?
MWE:
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,30
node at (i,0) [rectangle,label=above:i] (vi) $i$;
% here I want to make the label of node v7 to become $varnothing$
endtikzpicture
enddocument
Note: this has nothing to do with animation, I just want to create the nodes in a loop and then change labels for some of them.
UPD: I corrected MWE, as the original one was not exactly what I implied.
tikz-pgf tikz-node
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I need to draw many nodes with labels that I can calculate from their indices. However, a small amount of them do not follow the rule, thus I need to assign their labels manually. Can I do that somehow?
MWE:
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,30
node at (i,0) [rectangle,label=above:i] (vi) $i$;
% here I want to make the label of node v7 to become $varnothing$
endtikzpicture
enddocument
Note: this has nothing to do with animation, I just want to create the nodes in a loop and then change labels for some of them.
UPD: I corrected MWE, as the original one was not exactly what I implied.
tikz-pgf tikz-node
I need to draw many nodes with labels that I can calculate from their indices. However, a small amount of them do not follow the rule, thus I need to assign their labels manually. Can I do that somehow?
MWE:
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,30
node at (i,0) [rectangle,label=above:i] (vi) $i$;
% here I want to make the label of node v7 to become $varnothing$
endtikzpicture
enddocument
Note: this has nothing to do with animation, I just want to create the nodes in a loop and then change labels for some of them.
UPD: I corrected MWE, as the original one was not exactly what I implied.
tikz-pgf tikz-node
tikz-pgf tikz-node
edited Aug 13 at 16:22
asked Aug 13 at 12:14
Yauhen Yakimenka
145119
145119
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
7
down vote
accepted
You can use node also, which is described on p. 250 of the pgfmanual, for that.
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
node at (i,0) [rectangle,label=above:$ i $] (vi) $i$;
foreach i in 3,6,8
node also [label=[fill=white]above:$ varnothing $] (vi);
endtikzpicture
enddocument

BIG THANKS TO MAX for the edit.
Just in case you ever have wider labels: give the labels names and use their width for Max' fill=white trick.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarycalc
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,2,...,10
node at (i,0) [rectangle,label=[name=labi]above:$ii$] (vi) $i$;
foreach i in 3,6,10
path let p1=($(labi.north east)-(labi.south west)$) in node also
[label=[fill=white,minimum width=x1,minimum height=y1]above:$ varnothing $] (vi);
endtikzpicture
enddocument
ADDENDUM: Just for curiosity I was wondering if there is a simple way to make Max' nice answer work with lists. I am sure there is and leave it to others to use some xparse or other magic. Here I just want to report an irony of fate. If one goes for the built-in LaTeX check whether or not something is an element of a list, then my naive attempt fails for two digits, precisely where the simplest version of the above also starts to go wrong. Rather funny and ironic, I'd say. ;-)
documentclass[tikz]standalone
makeatletter
% https://tex.stackexchange.com/a/260921/121799 and https://tex.stackexchange.com/a/287094/121799
newcommandifmember[2]%
in@#1#2%
ifin@
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
edeftempnoexpandifmemberi3,6,9varnothingi
node at (i,0) [rectangle,label=above:$temp$] (vi) $ i $;
endtikzpicture
enddocument
Perhaps, my MWE was not exactly what I meant. I assumed that every node got a label in a loop, and then I want to change it. I.e. it is node at (i,0) [rectangle,label=above:i] (vi) $i$; If I try to do that with node also I end up with two labels, one over another.
â Yauhen Yakimenka
Aug 13 at 12:31
I updated MWE to reflect what I mean.
â Yauhen Yakimenka
Aug 13 at 12:36
2
@YauhenYakimenka You could of course dolabel=[fill=white]above:$varnothing$, then you wouldn't see the underlying label. That would be simpler than my answer if you have some more different labels.
â Max
Aug 13 at 12:50
1
@marmot I took the liberty of editing your answer, if you don't agree, please roll it back or edit it further.
â Max
Aug 13 at 13:36
1
@Max I actually think the conditionals in the loop are cleaner. If one were to replace the label10, there would be some leftover. Why don't you undelete your nice answer? (Having said this, I also realize that one could make thenode alsowork then by giving the labels also names and then using their width.)
â marmot
Aug 13 at 16:22
 |Â
show 4 more comments
up vote
4
down vote
You can use conditionals inside the foreach loop:
documentclass[tikz]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
ifnumi=7
node at (i,0) [rectangle,label=above:$ varnothing $] (vi) $ i $;
else
node at (i,0) [rectangle,label=above:$ i $] (vi) $ i $;
fi
% here I want to make the label of node v7 to become $varnothing$
endtikzpicture
enddocument

If you have more labels that should be different, the code stays more readable if you use pgfmathparse to do check the conditional:
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,2,...,10
pgfmathparse
ifthenelse(i==3,
"varnothing",
ifthenelse(i==7,
"varnothing",
ifthenelse(i==10,
"varnothing",
"i"
)
)
)
defmyLabelcsnamepgfmathresultendcsname
node at (i,0) [rectangle,label=above:$ myLabel $] (vi) $i$;
endtikzpicture
enddocument

add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
You can use node also, which is described on p. 250 of the pgfmanual, for that.
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
node at (i,0) [rectangle,label=above:$ i $] (vi) $i$;
foreach i in 3,6,8
node also [label=[fill=white]above:$ varnothing $] (vi);
endtikzpicture
enddocument

BIG THANKS TO MAX for the edit.
Just in case you ever have wider labels: give the labels names and use their width for Max' fill=white trick.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarycalc
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,2,...,10
node at (i,0) [rectangle,label=[name=labi]above:$ii$] (vi) $i$;
foreach i in 3,6,10
path let p1=($(labi.north east)-(labi.south west)$) in node also
[label=[fill=white,minimum width=x1,minimum height=y1]above:$ varnothing $] (vi);
endtikzpicture
enddocument
ADDENDUM: Just for curiosity I was wondering if there is a simple way to make Max' nice answer work with lists. I am sure there is and leave it to others to use some xparse or other magic. Here I just want to report an irony of fate. If one goes for the built-in LaTeX check whether or not something is an element of a list, then my naive attempt fails for two digits, precisely where the simplest version of the above also starts to go wrong. Rather funny and ironic, I'd say. ;-)
documentclass[tikz]standalone
makeatletter
% https://tex.stackexchange.com/a/260921/121799 and https://tex.stackexchange.com/a/287094/121799
newcommandifmember[2]%
in@#1#2%
ifin@
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
edeftempnoexpandifmemberi3,6,9varnothingi
node at (i,0) [rectangle,label=above:$temp$] (vi) $ i $;
endtikzpicture
enddocument
Perhaps, my MWE was not exactly what I meant. I assumed that every node got a label in a loop, and then I want to change it. I.e. it is node at (i,0) [rectangle,label=above:i] (vi) $i$; If I try to do that with node also I end up with two labels, one over another.
â Yauhen Yakimenka
Aug 13 at 12:31
I updated MWE to reflect what I mean.
â Yauhen Yakimenka
Aug 13 at 12:36
2
@YauhenYakimenka You could of course dolabel=[fill=white]above:$varnothing$, then you wouldn't see the underlying label. That would be simpler than my answer if you have some more different labels.
â Max
Aug 13 at 12:50
1
@marmot I took the liberty of editing your answer, if you don't agree, please roll it back or edit it further.
â Max
Aug 13 at 13:36
1
@Max I actually think the conditionals in the loop are cleaner. If one were to replace the label10, there would be some leftover. Why don't you undelete your nice answer? (Having said this, I also realize that one could make thenode alsowork then by giving the labels also names and then using their width.)
â marmot
Aug 13 at 16:22
 |Â
show 4 more comments
up vote
7
down vote
accepted
You can use node also, which is described on p. 250 of the pgfmanual, for that.
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
node at (i,0) [rectangle,label=above:$ i $] (vi) $i$;
foreach i in 3,6,8
node also [label=[fill=white]above:$ varnothing $] (vi);
endtikzpicture
enddocument

BIG THANKS TO MAX for the edit.
Just in case you ever have wider labels: give the labels names and use their width for Max' fill=white trick.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarycalc
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,2,...,10
node at (i,0) [rectangle,label=[name=labi]above:$ii$] (vi) $i$;
foreach i in 3,6,10
path let p1=($(labi.north east)-(labi.south west)$) in node also
[label=[fill=white,minimum width=x1,minimum height=y1]above:$ varnothing $] (vi);
endtikzpicture
enddocument
ADDENDUM: Just for curiosity I was wondering if there is a simple way to make Max' nice answer work with lists. I am sure there is and leave it to others to use some xparse or other magic. Here I just want to report an irony of fate. If one goes for the built-in LaTeX check whether or not something is an element of a list, then my naive attempt fails for two digits, precisely where the simplest version of the above also starts to go wrong. Rather funny and ironic, I'd say. ;-)
documentclass[tikz]standalone
makeatletter
% https://tex.stackexchange.com/a/260921/121799 and https://tex.stackexchange.com/a/287094/121799
newcommandifmember[2]%
in@#1#2%
ifin@
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
edeftempnoexpandifmemberi3,6,9varnothingi
node at (i,0) [rectangle,label=above:$temp$] (vi) $ i $;
endtikzpicture
enddocument
Perhaps, my MWE was not exactly what I meant. I assumed that every node got a label in a loop, and then I want to change it. I.e. it is node at (i,0) [rectangle,label=above:i] (vi) $i$; If I try to do that with node also I end up with two labels, one over another.
â Yauhen Yakimenka
Aug 13 at 12:31
I updated MWE to reflect what I mean.
â Yauhen Yakimenka
Aug 13 at 12:36
2
@YauhenYakimenka You could of course dolabel=[fill=white]above:$varnothing$, then you wouldn't see the underlying label. That would be simpler than my answer if you have some more different labels.
â Max
Aug 13 at 12:50
1
@marmot I took the liberty of editing your answer, if you don't agree, please roll it back or edit it further.
â Max
Aug 13 at 13:36
1
@Max I actually think the conditionals in the loop are cleaner. If one were to replace the label10, there would be some leftover. Why don't you undelete your nice answer? (Having said this, I also realize that one could make thenode alsowork then by giving the labels also names and then using their width.)
â marmot
Aug 13 at 16:22
 |Â
show 4 more comments
up vote
7
down vote
accepted
up vote
7
down vote
accepted
You can use node also, which is described on p. 250 of the pgfmanual, for that.
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
node at (i,0) [rectangle,label=above:$ i $] (vi) $i$;
foreach i in 3,6,8
node also [label=[fill=white]above:$ varnothing $] (vi);
endtikzpicture
enddocument

BIG THANKS TO MAX for the edit.
Just in case you ever have wider labels: give the labels names and use their width for Max' fill=white trick.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarycalc
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,2,...,10
node at (i,0) [rectangle,label=[name=labi]above:$ii$] (vi) $i$;
foreach i in 3,6,10
path let p1=($(labi.north east)-(labi.south west)$) in node also
[label=[fill=white,minimum width=x1,minimum height=y1]above:$ varnothing $] (vi);
endtikzpicture
enddocument
ADDENDUM: Just for curiosity I was wondering if there is a simple way to make Max' nice answer work with lists. I am sure there is and leave it to others to use some xparse or other magic. Here I just want to report an irony of fate. If one goes for the built-in LaTeX check whether or not something is an element of a list, then my naive attempt fails for two digits, precisely where the simplest version of the above also starts to go wrong. Rather funny and ironic, I'd say. ;-)
documentclass[tikz]standalone
makeatletter
% https://tex.stackexchange.com/a/260921/121799 and https://tex.stackexchange.com/a/287094/121799
newcommandifmember[2]%
in@#1#2%
ifin@
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
edeftempnoexpandifmemberi3,6,9varnothingi
node at (i,0) [rectangle,label=above:$temp$] (vi) $ i $;
endtikzpicture
enddocument
You can use node also, which is described on p. 250 of the pgfmanual, for that.
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
node at (i,0) [rectangle,label=above:$ i $] (vi) $i$;
foreach i in 3,6,8
node also [label=[fill=white]above:$ varnothing $] (vi);
endtikzpicture
enddocument

BIG THANKS TO MAX for the edit.
Just in case you ever have wider labels: give the labels names and use their width for Max' fill=white trick.
documentclass[tikz,border=3.14mm]standalone
usetikzlibrarycalc
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,2,...,10
node at (i,0) [rectangle,label=[name=labi]above:$ii$] (vi) $i$;
foreach i in 3,6,10
path let p1=($(labi.north east)-(labi.south west)$) in node also
[label=[fill=white,minimum width=x1,minimum height=y1]above:$ varnothing $] (vi);
endtikzpicture
enddocument
ADDENDUM: Just for curiosity I was wondering if there is a simple way to make Max' nice answer work with lists. I am sure there is and leave it to others to use some xparse or other magic. Here I just want to report an irony of fate. If one goes for the built-in LaTeX check whether or not something is an element of a list, then my naive attempt fails for two digits, precisely where the simplest version of the above also starts to go wrong. Rather funny and ironic, I'd say. ;-)
documentclass[tikz]standalone
makeatletter
% https://tex.stackexchange.com/a/260921/121799 and https://tex.stackexchange.com/a/287094/121799
newcommandifmember[2]%
in@#1#2%
ifin@
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
edeftempnoexpandifmemberi3,6,9varnothingi
node at (i,0) [rectangle,label=above:$temp$] (vi) $ i $;
endtikzpicture
enddocument
edited Aug 14 at 1:54
answered Aug 13 at 12:19
marmot
58k462124
58k462124
Perhaps, my MWE was not exactly what I meant. I assumed that every node got a label in a loop, and then I want to change it. I.e. it is node at (i,0) [rectangle,label=above:i] (vi) $i$; If I try to do that with node also I end up with two labels, one over another.
â Yauhen Yakimenka
Aug 13 at 12:31
I updated MWE to reflect what I mean.
â Yauhen Yakimenka
Aug 13 at 12:36
2
@YauhenYakimenka You could of course dolabel=[fill=white]above:$varnothing$, then you wouldn't see the underlying label. That would be simpler than my answer if you have some more different labels.
â Max
Aug 13 at 12:50
1
@marmot I took the liberty of editing your answer, if you don't agree, please roll it back or edit it further.
â Max
Aug 13 at 13:36
1
@Max I actually think the conditionals in the loop are cleaner. If one were to replace the label10, there would be some leftover. Why don't you undelete your nice answer? (Having said this, I also realize that one could make thenode alsowork then by giving the labels also names and then using their width.)
â marmot
Aug 13 at 16:22
 |Â
show 4 more comments
Perhaps, my MWE was not exactly what I meant. I assumed that every node got a label in a loop, and then I want to change it. I.e. it is node at (i,0) [rectangle,label=above:i] (vi) $i$; If I try to do that with node also I end up with two labels, one over another.
â Yauhen Yakimenka
Aug 13 at 12:31
I updated MWE to reflect what I mean.
â Yauhen Yakimenka
Aug 13 at 12:36
2
@YauhenYakimenka You could of course dolabel=[fill=white]above:$varnothing$, then you wouldn't see the underlying label. That would be simpler than my answer if you have some more different labels.
â Max
Aug 13 at 12:50
1
@marmot I took the liberty of editing your answer, if you don't agree, please roll it back or edit it further.
â Max
Aug 13 at 13:36
1
@Max I actually think the conditionals in the loop are cleaner. If one were to replace the label10, there would be some leftover. Why don't you undelete your nice answer? (Having said this, I also realize that one could make thenode alsowork then by giving the labels also names and then using their width.)
â marmot
Aug 13 at 16:22
Perhaps, my MWE was not exactly what I meant. I assumed that every node got a label in a loop, and then I want to change it. I.e. it is node at (i,0) [rectangle,label=above:i] (vi) $i$; If I try to do that with node also I end up with two labels, one over another.
â Yauhen Yakimenka
Aug 13 at 12:31
Perhaps, my MWE was not exactly what I meant. I assumed that every node got a label in a loop, and then I want to change it. I.e. it is node at (i,0) [rectangle,label=above:i] (vi) $i$; If I try to do that with node also I end up with two labels, one over another.
â Yauhen Yakimenka
Aug 13 at 12:31
I updated MWE to reflect what I mean.
â Yauhen Yakimenka
Aug 13 at 12:36
I updated MWE to reflect what I mean.
â Yauhen Yakimenka
Aug 13 at 12:36
2
2
@YauhenYakimenka You could of course do
label=[fill=white]above:$varnothing$, then you wouldn't see the underlying label. That would be simpler than my answer if you have some more different labels.â Max
Aug 13 at 12:50
@YauhenYakimenka You could of course do
label=[fill=white]above:$varnothing$, then you wouldn't see the underlying label. That would be simpler than my answer if you have some more different labels.â Max
Aug 13 at 12:50
1
1
@marmot I took the liberty of editing your answer, if you don't agree, please roll it back or edit it further.
â Max
Aug 13 at 13:36
@marmot I took the liberty of editing your answer, if you don't agree, please roll it back or edit it further.
â Max
Aug 13 at 13:36
1
1
@Max I actually think the conditionals in the loop are cleaner. If one were to replace the label
10, there would be some leftover. Why don't you undelete your nice answer? (Having said this, I also realize that one could make the node also work then by giving the labels also names and then using their width.)â marmot
Aug 13 at 16:22
@Max I actually think the conditionals in the loop are cleaner. If one were to replace the label
10, there would be some leftover. Why don't you undelete your nice answer? (Having said this, I also realize that one could make the node also work then by giving the labels also names and then using their width.)â marmot
Aug 13 at 16:22
 |Â
show 4 more comments
up vote
4
down vote
You can use conditionals inside the foreach loop:
documentclass[tikz]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
ifnumi=7
node at (i,0) [rectangle,label=above:$ varnothing $] (vi) $ i $;
else
node at (i,0) [rectangle,label=above:$ i $] (vi) $ i $;
fi
% here I want to make the label of node v7 to become $varnothing$
endtikzpicture
enddocument

If you have more labels that should be different, the code stays more readable if you use pgfmathparse to do check the conditional:
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,2,...,10
pgfmathparse
ifthenelse(i==3,
"varnothing",
ifthenelse(i==7,
"varnothing",
ifthenelse(i==10,
"varnothing",
"i"
)
)
)
defmyLabelcsnamepgfmathresultendcsname
node at (i,0) [rectangle,label=above:$ myLabel $] (vi) $i$;
endtikzpicture
enddocument

add a comment |Â
up vote
4
down vote
You can use conditionals inside the foreach loop:
documentclass[tikz]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
ifnumi=7
node at (i,0) [rectangle,label=above:$ varnothing $] (vi) $ i $;
else
node at (i,0) [rectangle,label=above:$ i $] (vi) $ i $;
fi
% here I want to make the label of node v7 to become $varnothing$
endtikzpicture
enddocument

If you have more labels that should be different, the code stays more readable if you use pgfmathparse to do check the conditional:
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,2,...,10
pgfmathparse
ifthenelse(i==3,
"varnothing",
ifthenelse(i==7,
"varnothing",
ifthenelse(i==10,
"varnothing",
"i"
)
)
)
defmyLabelcsnamepgfmathresultendcsname
node at (i,0) [rectangle,label=above:$ myLabel $] (vi) $i$;
endtikzpicture
enddocument

add a comment |Â
up vote
4
down vote
up vote
4
down vote
You can use conditionals inside the foreach loop:
documentclass[tikz]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
ifnumi=7
node at (i,0) [rectangle,label=above:$ varnothing $] (vi) $ i $;
else
node at (i,0) [rectangle,label=above:$ i $] (vi) $ i $;
fi
% here I want to make the label of node v7 to become $varnothing$
endtikzpicture
enddocument

If you have more labels that should be different, the code stays more readable if you use pgfmathparse to do check the conditional:
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,2,...,10
pgfmathparse
ifthenelse(i==3,
"varnothing",
ifthenelse(i==7,
"varnothing",
ifthenelse(i==10,
"varnothing",
"i"
)
)
)
defmyLabelcsnamepgfmathresultendcsname
node at (i,0) [rectangle,label=above:$ myLabel $] (vi) $i$;
endtikzpicture
enddocument

You can use conditionals inside the foreach loop:
documentclass[tikz]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,...,10
ifnumi=7
node at (i,0) [rectangle,label=above:$ varnothing $] (vi) $ i $;
else
node at (i,0) [rectangle,label=above:$ i $] (vi) $ i $;
fi
% here I want to make the label of node v7 to become $varnothing$
endtikzpicture
enddocument

If you have more labels that should be different, the code stays more readable if you use pgfmathparse to do check the conditional:
documentclass[tikz,border=3.14mm]standalone
usepackageamssymb
begindocument
begintikzpicture
foreach i in 1,2,...,10
pgfmathparse
ifthenelse(i==3,
"varnothing",
ifthenelse(i==7,
"varnothing",
ifthenelse(i==10,
"varnothing",
"i"
)
)
)
defmyLabelcsnamepgfmathresultendcsname
node at (i,0) [rectangle,label=above:$ myLabel $] (vi) $i$;
endtikzpicture
enddocument

edited Aug 13 at 17:48
answered Aug 13 at 12:36
Max
6,18311728
6,18311728
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f445871%2ftikz-redefine-update-node-label%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password