TikZ: redefine/update node label

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












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.










share|improve this question



























    up vote
    5
    down vote

    favorite
    1












    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.










    share|improve this question

























      up vote
      5
      down vote

      favorite
      1









      up vote
      5
      down vote

      favorite
      1






      1





      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 13 at 16:22

























      asked Aug 13 at 12:14









      Yauhen Yakimenka

      145119




      145119




















          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


          enter image description here



          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





          share|improve this answer






















          • 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 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




            @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 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


















          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


          enter image description here



          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


          enter image description here






          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "85"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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






























            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


            enter image description here



            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





            share|improve this answer






















            • 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 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




              @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 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















            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


            enter image description here



            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





            share|improve this answer






















            • 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 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




              @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 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













            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


            enter image description here



            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





            share|improve this answer














            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


            enter image description here



            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






            share|improve this answer














            share|improve this answer



            share|improve this answer








            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 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




              @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 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

















            • 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 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




              @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 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
















            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











            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


            enter image description here



            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


            enter image description here






            share|improve this answer


























              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


              enter image description here



              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


              enter image description here






              share|improve this answer
























                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


                enter image description here



                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


                enter image description here






                share|improve this answer














                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


                enter image description here



                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


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 13 at 17:48

























                answered Aug 13 at 12:36









                Max

                6,18311728




                6,18311728



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?