Call for node distance as a variable in TikZ












5















Is it possible to use the node distance as a variable while expressing coordinates of new nodes with Calc and Positioning libraries? What I want to have is everything within a single piece of code for tikz picture.



This is what I have now.



documentclass[12pt, a4paper]{article}
usepackage{tikz}
usetikzlibrary{automata, positioning, arrows,calc}

begin{document}
begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,node distance=2cm,semithick,on grid]

tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
node[state,label=center:$a$,inner sep=0pt] (a) {};
node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:1cm) $) {};
node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:1cm)$) {};

path[->] (a) edge node {$1$} (b)
(c) edge node[right] {$1$} (b)
(b) edge [loop right] node[above] {$0,1$} (b);
path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

end{tikzpicture}
end{document}


I would like to be able to change the below expression with something like:



$(a) + sqrt(1/3)*2*(1:nodedistance)$


Then if I would be copying the code elsewhere, such as a presentations, I would be able to change all these distances at once. Is that possible? If not, introducing a variable in the first line of the TikZ code, and using it afterwards instead the "nodedistance", would also do.



Sorry if it's a dull question, I'm pretty new to TikZ.










share|improve this question







New contributor




gari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Welcome to TeX.SE! This is not at all a dumb question. Are you aware of this post, I guess that /tikz/node distance/.append code={...} does what you want. This allows you to store the distance in a key that you can use.

    – marmot
    6 hours ago
















5















Is it possible to use the node distance as a variable while expressing coordinates of new nodes with Calc and Positioning libraries? What I want to have is everything within a single piece of code for tikz picture.



This is what I have now.



documentclass[12pt, a4paper]{article}
usepackage{tikz}
usetikzlibrary{automata, positioning, arrows,calc}

begin{document}
begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,node distance=2cm,semithick,on grid]

tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
node[state,label=center:$a$,inner sep=0pt] (a) {};
node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:1cm) $) {};
node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:1cm)$) {};

path[->] (a) edge node {$1$} (b)
(c) edge node[right] {$1$} (b)
(b) edge [loop right] node[above] {$0,1$} (b);
path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

end{tikzpicture}
end{document}


I would like to be able to change the below expression with something like:



$(a) + sqrt(1/3)*2*(1:nodedistance)$


Then if I would be copying the code elsewhere, such as a presentations, I would be able to change all these distances at once. Is that possible? If not, introducing a variable in the first line of the TikZ code, and using it afterwards instead the "nodedistance", would also do.



Sorry if it's a dull question, I'm pretty new to TikZ.










share|improve this question







New contributor




gari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Welcome to TeX.SE! This is not at all a dumb question. Are you aware of this post, I guess that /tikz/node distance/.append code={...} does what you want. This allows you to store the distance in a key that you can use.

    – marmot
    6 hours ago














5












5








5








Is it possible to use the node distance as a variable while expressing coordinates of new nodes with Calc and Positioning libraries? What I want to have is everything within a single piece of code for tikz picture.



This is what I have now.



documentclass[12pt, a4paper]{article}
usepackage{tikz}
usetikzlibrary{automata, positioning, arrows,calc}

begin{document}
begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,node distance=2cm,semithick,on grid]

tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
node[state,label=center:$a$,inner sep=0pt] (a) {};
node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:1cm) $) {};
node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:1cm)$) {};

path[->] (a) edge node {$1$} (b)
(c) edge node[right] {$1$} (b)
(b) edge [loop right] node[above] {$0,1$} (b);
path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

end{tikzpicture}
end{document}


I would like to be able to change the below expression with something like:



$(a) + sqrt(1/3)*2*(1:nodedistance)$


Then if I would be copying the code elsewhere, such as a presentations, I would be able to change all these distances at once. Is that possible? If not, introducing a variable in the first line of the TikZ code, and using it afterwards instead the "nodedistance", would also do.



Sorry if it's a dull question, I'm pretty new to TikZ.










share|improve this question







New contributor




gari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












Is it possible to use the node distance as a variable while expressing coordinates of new nodes with Calc and Positioning libraries? What I want to have is everything within a single piece of code for tikz picture.



This is what I have now.



documentclass[12pt, a4paper]{article}
usepackage{tikz}
usetikzlibrary{automata, positioning, arrows,calc}

begin{document}
begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,node distance=2cm,semithick,on grid]

tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
node[state,label=center:$a$,inner sep=0pt] (a) {};
node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:1cm) $) {};
node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:1cm)$) {};

path[->] (a) edge node {$1$} (b)
(c) edge node[right] {$1$} (b)
(b) edge [loop right] node[above] {$0,1$} (b);
path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

end{tikzpicture}
end{document}


I would like to be able to change the below expression with something like:



$(a) + sqrt(1/3)*2*(1:nodedistance)$


Then if I would be copying the code elsewhere, such as a presentations, I would be able to change all these distances at once. Is that possible? If not, introducing a variable in the first line of the TikZ code, and using it afterwards instead the "nodedistance", would also do.



Sorry if it's a dull question, I'm pretty new to TikZ.







tikz-pgf positioning nodes calc






share|improve this question







New contributor




gari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




gari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




gari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 7 hours ago









garigari

262




262




New contributor




gari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





gari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






gari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Welcome to TeX.SE! This is not at all a dumb question. Are you aware of this post, I guess that /tikz/node distance/.append code={...} does what you want. This allows you to store the distance in a key that you can use.

    – marmot
    6 hours ago



















  • Welcome to TeX.SE! This is not at all a dumb question. Are you aware of this post, I guess that /tikz/node distance/.append code={...} does what you want. This allows you to store the distance in a key that you can use.

    – marmot
    6 hours ago

















Welcome to TeX.SE! This is not at all a dumb question. Are you aware of this post, I guess that /tikz/node distance/.append code={...} does what you want. This allows you to store the distance in a key that you can use.

– marmot
6 hours ago





Welcome to TeX.SE! This is not at all a dumb question. Are you aware of this post, I guess that /tikz/node distance/.append code={...} does what you want. This allows you to store the distance in a key that you can use.

– marmot
6 hours ago










2 Answers
2






active

oldest

votes


















3














AFAIK you cannot simply read off the value of /tikz/node distance. However, in this great answer by @Jake there is a simple way to amend node distance by a pgf key that you can use.



documentclass[12pt, a4paper]{article}
usepackage{tikz}
usetikzlibrary{automata, positioning, arrows,calc}
tikzset{node distance/.append code={
pgfkeyssetvalue{/tikz/node distance value}{#1}
}}
begin{document}
begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,node
distance=2cm,semithick,on grid,
every state/.style={minimum size=20pt, fill=none,draw=black}]
node[state,label=center:$a$,inner sep=0pt] (a) {};
node[state,label=center:$b$] (b) at ($(a) + sqrt(4/3)*(0:pgfkeysvalueof{/tikz/node distance value}) $) {};
node[state,label=center:$c$] (c) at ($(a) + sqrt(4/3)*(-60:pgfkeysvalueof{/tikz/node distance value})$) {};

path[->] (a) edge node {$1$} (b)
(c) edge node[right] {$1$} (b)
(b) edge [loop right] node[above] {$0,1$} (b);
path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);
end{tikzpicture}
end{document}


enter image description here






share|improve this answer































    0














    You can create a macro defnodedistance{1cm} at the begining of the tikzpicture . Later if needed this macro could be redefined .



    documentclass[12pt, a4paper]{article}
    usepackage{tikz}
    usetikzlibrary{automata, positioning, arrows,calc}

    begin{document}
    begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

    defnodedistance{1cm} % <------------

    tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
    node[state,label=center:$a$,inner sep=0pt] (a) {};
    node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:nodedistance) $) {};
    node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:nodedistance)$) {};

    path[->] (a) edge node {$1$} (b)
    (c) edge node[right] {$1$} (b)
    (b) edge [loop right] node[above] {$0,1$} (b);
    path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

    end{tikzpicture}

    begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

    defnodedistance{2cm} % <----------------

    tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
    node[state,label=center:$a$,inner sep=0pt] (a) {};
    node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:nodedistance) $) {};
    node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:nodedistance)$) {};

    path[->] (a) edge node {$1$} (b)
    (c) edge node[right] {$1$} (b)
    (b) edge [loop right] node[above] {$0,1$} (b);
    path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

    end{tikzpicture}
    end{document}


    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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });






      gari is a new contributor. Be nice, and check out our Code of Conduct.










      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f473114%2fcall-for-node-distance-as-a-variable-in-tikz%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      AFAIK you cannot simply read off the value of /tikz/node distance. However, in this great answer by @Jake there is a simple way to amend node distance by a pgf key that you can use.



      documentclass[12pt, a4paper]{article}
      usepackage{tikz}
      usetikzlibrary{automata, positioning, arrows,calc}
      tikzset{node distance/.append code={
      pgfkeyssetvalue{/tikz/node distance value}{#1}
      }}
      begin{document}
      begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,node
      distance=2cm,semithick,on grid,
      every state/.style={minimum size=20pt, fill=none,draw=black}]
      node[state,label=center:$a$,inner sep=0pt] (a) {};
      node[state,label=center:$b$] (b) at ($(a) + sqrt(4/3)*(0:pgfkeysvalueof{/tikz/node distance value}) $) {};
      node[state,label=center:$c$] (c) at ($(a) + sqrt(4/3)*(-60:pgfkeysvalueof{/tikz/node distance value})$) {};

      path[->] (a) edge node {$1$} (b)
      (c) edge node[right] {$1$} (b)
      (b) edge [loop right] node[above] {$0,1$} (b);
      path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);
      end{tikzpicture}
      end{document}


      enter image description here






      share|improve this answer




























        3














        AFAIK you cannot simply read off the value of /tikz/node distance. However, in this great answer by @Jake there is a simple way to amend node distance by a pgf key that you can use.



        documentclass[12pt, a4paper]{article}
        usepackage{tikz}
        usetikzlibrary{automata, positioning, arrows,calc}
        tikzset{node distance/.append code={
        pgfkeyssetvalue{/tikz/node distance value}{#1}
        }}
        begin{document}
        begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,node
        distance=2cm,semithick,on grid,
        every state/.style={minimum size=20pt, fill=none,draw=black}]
        node[state,label=center:$a$,inner sep=0pt] (a) {};
        node[state,label=center:$b$] (b) at ($(a) + sqrt(4/3)*(0:pgfkeysvalueof{/tikz/node distance value}) $) {};
        node[state,label=center:$c$] (c) at ($(a) + sqrt(4/3)*(-60:pgfkeysvalueof{/tikz/node distance value})$) {};

        path[->] (a) edge node {$1$} (b)
        (c) edge node[right] {$1$} (b)
        (b) edge [loop right] node[above] {$0,1$} (b);
        path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);
        end{tikzpicture}
        end{document}


        enter image description here






        share|improve this answer


























          3












          3








          3







          AFAIK you cannot simply read off the value of /tikz/node distance. However, in this great answer by @Jake there is a simple way to amend node distance by a pgf key that you can use.



          documentclass[12pt, a4paper]{article}
          usepackage{tikz}
          usetikzlibrary{automata, positioning, arrows,calc}
          tikzset{node distance/.append code={
          pgfkeyssetvalue{/tikz/node distance value}{#1}
          }}
          begin{document}
          begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,node
          distance=2cm,semithick,on grid,
          every state/.style={minimum size=20pt, fill=none,draw=black}]
          node[state,label=center:$a$,inner sep=0pt] (a) {};
          node[state,label=center:$b$] (b) at ($(a) + sqrt(4/3)*(0:pgfkeysvalueof{/tikz/node distance value}) $) {};
          node[state,label=center:$c$] (c) at ($(a) + sqrt(4/3)*(-60:pgfkeysvalueof{/tikz/node distance value})$) {};

          path[->] (a) edge node {$1$} (b)
          (c) edge node[right] {$1$} (b)
          (b) edge [loop right] node[above] {$0,1$} (b);
          path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer













          AFAIK you cannot simply read off the value of /tikz/node distance. However, in this great answer by @Jake there is a simple way to amend node distance by a pgf key that you can use.



          documentclass[12pt, a4paper]{article}
          usepackage{tikz}
          usetikzlibrary{automata, positioning, arrows,calc}
          tikzset{node distance/.append code={
          pgfkeyssetvalue{/tikz/node distance value}{#1}
          }}
          begin{document}
          begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,node
          distance=2cm,semithick,on grid,
          every state/.style={minimum size=20pt, fill=none,draw=black}]
          node[state,label=center:$a$,inner sep=0pt] (a) {};
          node[state,label=center:$b$] (b) at ($(a) + sqrt(4/3)*(0:pgfkeysvalueof{/tikz/node distance value}) $) {};
          node[state,label=center:$c$] (c) at ($(a) + sqrt(4/3)*(-60:pgfkeysvalueof{/tikz/node distance value})$) {};

          path[->] (a) edge node {$1$} (b)
          (c) edge node[right] {$1$} (b)
          (b) edge [loop right] node[above] {$0,1$} (b);
          path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);
          end{tikzpicture}
          end{document}


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 6 hours ago









          marmotmarmot

          96.7k4111213




          96.7k4111213























              0














              You can create a macro defnodedistance{1cm} at the begining of the tikzpicture . Later if needed this macro could be redefined .



              documentclass[12pt, a4paper]{article}
              usepackage{tikz}
              usetikzlibrary{automata, positioning, arrows,calc}

              begin{document}
              begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

              defnodedistance{1cm} % <------------

              tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
              node[state,label=center:$a$,inner sep=0pt] (a) {};
              node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:nodedistance) $) {};
              node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:nodedistance)$) {};

              path[->] (a) edge node {$1$} (b)
              (c) edge node[right] {$1$} (b)
              (b) edge [loop right] node[above] {$0,1$} (b);
              path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

              end{tikzpicture}

              begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

              defnodedistance{2cm} % <----------------

              tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
              node[state,label=center:$a$,inner sep=0pt] (a) {};
              node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:nodedistance) $) {};
              node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:nodedistance)$) {};

              path[->] (a) edge node {$1$} (b)
              (c) edge node[right] {$1$} (b)
              (b) edge [loop right] node[above] {$0,1$} (b);
              path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

              end{tikzpicture}
              end{document}


              enter image description here






              share|improve this answer






























                0














                You can create a macro defnodedistance{1cm} at the begining of the tikzpicture . Later if needed this macro could be redefined .



                documentclass[12pt, a4paper]{article}
                usepackage{tikz}
                usetikzlibrary{automata, positioning, arrows,calc}

                begin{document}
                begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

                defnodedistance{1cm} % <------------

                tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
                node[state,label=center:$a$,inner sep=0pt] (a) {};
                node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:nodedistance) $) {};
                node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:nodedistance)$) {};

                path[->] (a) edge node {$1$} (b)
                (c) edge node[right] {$1$} (b)
                (b) edge [loop right] node[above] {$0,1$} (b);
                path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

                end{tikzpicture}

                begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

                defnodedistance{2cm} % <----------------

                tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
                node[state,label=center:$a$,inner sep=0pt] (a) {};
                node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:nodedistance) $) {};
                node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:nodedistance)$) {};

                path[->] (a) edge node {$1$} (b)
                (c) edge node[right] {$1$} (b)
                (b) edge [loop right] node[above] {$0,1$} (b);
                path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

                end{tikzpicture}
                end{document}


                enter image description here






                share|improve this answer




























                  0












                  0








                  0







                  You can create a macro defnodedistance{1cm} at the begining of the tikzpicture . Later if needed this macro could be redefined .



                  documentclass[12pt, a4paper]{article}
                  usepackage{tikz}
                  usetikzlibrary{automata, positioning, arrows,calc}

                  begin{document}
                  begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

                  defnodedistance{1cm} % <------------

                  tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
                  node[state,label=center:$a$,inner sep=0pt] (a) {};
                  node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:nodedistance) $) {};
                  node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:nodedistance)$) {};

                  path[->] (a) edge node {$1$} (b)
                  (c) edge node[right] {$1$} (b)
                  (b) edge [loop right] node[above] {$0,1$} (b);
                  path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

                  end{tikzpicture}

                  begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

                  defnodedistance{2cm} % <----------------

                  tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
                  node[state,label=center:$a$,inner sep=0pt] (a) {};
                  node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:nodedistance) $) {};
                  node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:nodedistance)$) {};

                  path[->] (a) edge node {$1$} (b)
                  (c) edge node[right] {$1$} (b)
                  (b) edge [loop right] node[above] {$0,1$} (b);
                  path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

                  end{tikzpicture}
                  end{document}


                  enter image description here






                  share|improve this answer















                  You can create a macro defnodedistance{1cm} at the begining of the tikzpicture . Later if needed this macro could be redefined .



                  documentclass[12pt, a4paper]{article}
                  usepackage{tikz}
                  usetikzlibrary{automata, positioning, arrows,calc}

                  begin{document}
                  begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

                  defnodedistance{1cm} % <------------

                  tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
                  node[state,label=center:$a$,inner sep=0pt] (a) {};
                  node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:nodedistance) $) {};
                  node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:nodedistance)$) {};

                  path[->] (a) edge node {$1$} (b)
                  (c) edge node[right] {$1$} (b)
                  (b) edge [loop right] node[above] {$0,1$} (b);
                  path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

                  end{tikzpicture}

                  begin{tikzpicture}[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

                  defnodedistance{2cm} % <----------------

                  tikzstyle{every state}=[minimum size=20pt, fill=none,draw=black]
                  node[state,label=center:$a$,inner sep=0pt] (a) {};
                  node[state,label=center:$b$] (b) at ($(a) + sqrt(1/3)*4*(0:nodedistance) $) {};
                  node[state,label=center:$c$] (c) at ($(a) + sqrt(1/3)*4*(-60:nodedistance)$) {};

                  path[->] (a) edge node {$1$} (b)
                  (c) edge node[right] {$1$} (b)
                  (b) edge [loop right] node[above] {$0,1$} (b);
                  path[shorten <=0.5pt,<->] (a) edge node[left]{$0$} (c);

                  end{tikzpicture}
                  end{document}


                  enter image description here







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 18 mins ago

























                  answered 26 mins ago









                  Hafid BoukhouldaHafid Boukhoulda

                  2,9271520




                  2,9271520






















                      gari is a new contributor. Be nice, and check out our Code of Conduct.










                      draft saved

                      draft discarded


















                      gari is a new contributor. Be nice, and check out our Code of Conduct.













                      gari is a new contributor. Be nice, and check out our Code of Conduct.












                      gari is a new contributor. Be nice, and check out our Code of Conduct.
















                      Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f473114%2fcall-for-node-distance-as-a-variable-in-tikz%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      GameSpot

                      日野市

                      Tu-95轟炸機