Call for node distance as a variable in TikZ

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












7















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
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc

begindocument
begintikzpicture[>=stealth',shorten >=0.5pt,auto,node distance=2cm,semithick,on grid]

tikzstyleevery 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);

endtikzpicture
enddocument


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

















  • 1





    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
    Feb 3 at 0:56















7















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
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc

begindocument
begintikzpicture[>=stealth',shorten >=0.5pt,auto,node distance=2cm,semithick,on grid]

tikzstyleevery 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);

endtikzpicture
enddocument


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

















  • 1





    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
    Feb 3 at 0:56













7












7








7








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
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc

begindocument
begintikzpicture[>=stealth',shorten >=0.5pt,auto,node distance=2cm,semithick,on grid]

tikzstyleevery 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);

endtikzpicture
enddocument


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














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
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc

begindocument
begintikzpicture[>=stealth',shorten >=0.5pt,auto,node distance=2cm,semithick,on grid]

tikzstyleevery 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);

endtikzpicture
enddocument


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













share|improve this question











share|improve this question




share|improve this question










asked Feb 3 at 0:38









garigari

384




384







  • 1





    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
    Feb 3 at 0:56












  • 1





    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
    Feb 3 at 0:56







1




1





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
Feb 3 at 0:56





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
Feb 3 at 0:56










2 Answers
2






active

oldest

votes


















6














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
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc
tikzsetnode distance/.append code=
pgfkeyssetvalue/tikz/node distance value#1

begindocument
begintikzpicture[>=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);
endtikzpicture
enddocument


enter image description here






share|improve this answer


















  • 1





    Thank you very much for your explanation, I haven't seen Jake's post before, or at least I haven't noticed that very detail I needed. Yes, this gives me exactly what I wanted - "the way it was meant to be done".

    – gari
    Feb 3 at 9:37







  • 2





    @gari please don't forget to accept this answer.

    – Hafid Boukhoulda
    Feb 3 at 16:58


















4














You can create a macro defnodedistance1cm at the begining of the tikzpicture . Later if needed this macro could be redefined .



documentclass[12pt, a4paper]article
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc

begindocument
begintikzpicture[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

defnodedistance1cm % <------------

tikzstyleevery 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);

endtikzpicture

begintikzpicture[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

defnodedistance2cm % <----------------

tikzstyleevery 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);

endtikzpicture
enddocument


enter image description here






share|improve this answer




















  • 1





    Thanks, this is quite elegant way to do it. While marmot's reply gives me the exact thing I needed, your reply offers more - in case I might want to have more than one default distances. Then one could do it like this - manually.

    – gari
    Feb 3 at 9:41






  • 2





    You can also use a length register: newlengthnodedistance and nodedistance=1cm.

    – John Kormylo
    Feb 3 at 19:07











  • Thanks, that's also a nice solution. I'll keep that in mind too.

    – gari
    Feb 3 at 20:24










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



);













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









6














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
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc
tikzsetnode distance/.append code=
pgfkeyssetvalue/tikz/node distance value#1

begindocument
begintikzpicture[>=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);
endtikzpicture
enddocument


enter image description here






share|improve this answer


















  • 1





    Thank you very much for your explanation, I haven't seen Jake's post before, or at least I haven't noticed that very detail I needed. Yes, this gives me exactly what I wanted - "the way it was meant to be done".

    – gari
    Feb 3 at 9:37







  • 2





    @gari please don't forget to accept this answer.

    – Hafid Boukhoulda
    Feb 3 at 16:58















6














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
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc
tikzsetnode distance/.append code=
pgfkeyssetvalue/tikz/node distance value#1

begindocument
begintikzpicture[>=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);
endtikzpicture
enddocument


enter image description here






share|improve this answer


















  • 1





    Thank you very much for your explanation, I haven't seen Jake's post before, or at least I haven't noticed that very detail I needed. Yes, this gives me exactly what I wanted - "the way it was meant to be done".

    – gari
    Feb 3 at 9:37







  • 2





    @gari please don't forget to accept this answer.

    – Hafid Boukhoulda
    Feb 3 at 16:58













6












6








6







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
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc
tikzsetnode distance/.append code=
pgfkeyssetvalue/tikz/node distance value#1

begindocument
begintikzpicture[>=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);
endtikzpicture
enddocument


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
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc
tikzsetnode distance/.append code=
pgfkeyssetvalue/tikz/node distance value#1

begindocument
begintikzpicture[>=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);
endtikzpicture
enddocument


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 3 at 1:04









marmotmarmot

103k4122233




103k4122233







  • 1





    Thank you very much for your explanation, I haven't seen Jake's post before, or at least I haven't noticed that very detail I needed. Yes, this gives me exactly what I wanted - "the way it was meant to be done".

    – gari
    Feb 3 at 9:37







  • 2





    @gari please don't forget to accept this answer.

    – Hafid Boukhoulda
    Feb 3 at 16:58












  • 1





    Thank you very much for your explanation, I haven't seen Jake's post before, or at least I haven't noticed that very detail I needed. Yes, this gives me exactly what I wanted - "the way it was meant to be done".

    – gari
    Feb 3 at 9:37







  • 2





    @gari please don't forget to accept this answer.

    – Hafid Boukhoulda
    Feb 3 at 16:58







1




1





Thank you very much for your explanation, I haven't seen Jake's post before, or at least I haven't noticed that very detail I needed. Yes, this gives me exactly what I wanted - "the way it was meant to be done".

– gari
Feb 3 at 9:37






Thank you very much for your explanation, I haven't seen Jake's post before, or at least I haven't noticed that very detail I needed. Yes, this gives me exactly what I wanted - "the way it was meant to be done".

– gari
Feb 3 at 9:37





2




2





@gari please don't forget to accept this answer.

– Hafid Boukhoulda
Feb 3 at 16:58





@gari please don't forget to accept this answer.

– Hafid Boukhoulda
Feb 3 at 16:58











4














You can create a macro defnodedistance1cm at the begining of the tikzpicture . Later if needed this macro could be redefined .



documentclass[12pt, a4paper]article
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc

begindocument
begintikzpicture[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

defnodedistance1cm % <------------

tikzstyleevery 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);

endtikzpicture

begintikzpicture[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

defnodedistance2cm % <----------------

tikzstyleevery 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);

endtikzpicture
enddocument


enter image description here






share|improve this answer




















  • 1





    Thanks, this is quite elegant way to do it. While marmot's reply gives me the exact thing I needed, your reply offers more - in case I might want to have more than one default distances. Then one could do it like this - manually.

    – gari
    Feb 3 at 9:41






  • 2





    You can also use a length register: newlengthnodedistance and nodedistance=1cm.

    – John Kormylo
    Feb 3 at 19:07











  • Thanks, that's also a nice solution. I'll keep that in mind too.

    – gari
    Feb 3 at 20:24















4














You can create a macro defnodedistance1cm at the begining of the tikzpicture . Later if needed this macro could be redefined .



documentclass[12pt, a4paper]article
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc

begindocument
begintikzpicture[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

defnodedistance1cm % <------------

tikzstyleevery 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);

endtikzpicture

begintikzpicture[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

defnodedistance2cm % <----------------

tikzstyleevery 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);

endtikzpicture
enddocument


enter image description here






share|improve this answer




















  • 1





    Thanks, this is quite elegant way to do it. While marmot's reply gives me the exact thing I needed, your reply offers more - in case I might want to have more than one default distances. Then one could do it like this - manually.

    – gari
    Feb 3 at 9:41






  • 2





    You can also use a length register: newlengthnodedistance and nodedistance=1cm.

    – John Kormylo
    Feb 3 at 19:07











  • Thanks, that's also a nice solution. I'll keep that in mind too.

    – gari
    Feb 3 at 20:24













4












4








4







You can create a macro defnodedistance1cm at the begining of the tikzpicture . Later if needed this macro could be redefined .



documentclass[12pt, a4paper]article
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc

begindocument
begintikzpicture[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

defnodedistance1cm % <------------

tikzstyleevery 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);

endtikzpicture

begintikzpicture[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

defnodedistance2cm % <----------------

tikzstyleevery 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);

endtikzpicture
enddocument


enter image description here






share|improve this answer















You can create a macro defnodedistance1cm at the begining of the tikzpicture . Later if needed this macro could be redefined .



documentclass[12pt, a4paper]article
usepackagetikz
usetikzlibraryautomata, positioning, arrows,calc

begindocument
begintikzpicture[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

defnodedistance1cm % <------------

tikzstyleevery 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);

endtikzpicture

begintikzpicture[>=stealth',shorten >=0.5pt,auto,semithick,on grid]

defnodedistance2cm % <----------------

tikzstyleevery 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);

endtikzpicture
enddocument


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 3 at 7:33

























answered Feb 3 at 7:24









Hafid BoukhouldaHafid Boukhoulda

4,0571624




4,0571624







  • 1





    Thanks, this is quite elegant way to do it. While marmot's reply gives me the exact thing I needed, your reply offers more - in case I might want to have more than one default distances. Then one could do it like this - manually.

    – gari
    Feb 3 at 9:41






  • 2





    You can also use a length register: newlengthnodedistance and nodedistance=1cm.

    – John Kormylo
    Feb 3 at 19:07











  • Thanks, that's also a nice solution. I'll keep that in mind too.

    – gari
    Feb 3 at 20:24












  • 1





    Thanks, this is quite elegant way to do it. While marmot's reply gives me the exact thing I needed, your reply offers more - in case I might want to have more than one default distances. Then one could do it like this - manually.

    – gari
    Feb 3 at 9:41






  • 2





    You can also use a length register: newlengthnodedistance and nodedistance=1cm.

    – John Kormylo
    Feb 3 at 19:07











  • Thanks, that's also a nice solution. I'll keep that in mind too.

    – gari
    Feb 3 at 20:24







1




1





Thanks, this is quite elegant way to do it. While marmot's reply gives me the exact thing I needed, your reply offers more - in case I might want to have more than one default distances. Then one could do it like this - manually.

– gari
Feb 3 at 9:41





Thanks, this is quite elegant way to do it. While marmot's reply gives me the exact thing I needed, your reply offers more - in case I might want to have more than one default distances. Then one could do it like this - manually.

– gari
Feb 3 at 9:41




2




2





You can also use a length register: newlengthnodedistance and nodedistance=1cm.

– John Kormylo
Feb 3 at 19:07





You can also use a length register: newlengthnodedistance and nodedistance=1cm.

– John Kormylo
Feb 3 at 19:07













Thanks, that's also a nice solution. I'll keep that in mind too.

– gari
Feb 3 at 20:24





Thanks, that's also a nice solution. I'll keep that in mind too.

– gari
Feb 3 at 20:24

















draft saved

draft discarded
















































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

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

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay