TikZ: How does global/local [node distance] work?
up vote
6
down vote
favorite
The expected output of this MWE is two overlaying nodes (i.e. B
and C
).
However, node [draw, right = 1cm of A] (B) {B};
successfully overrides the global setting of node distance=2cm
, while node [draw, right = of A, node distance = 1cm] (C) {C};
doesn't.
So, why do both syntaxes result in different outputs?
documentclass[border=1cm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, right = of A, node distance = 1cm] (C) {C};
end{tikzpicture}
end{document}
tikz-pgf
add a comment |
up vote
6
down vote
favorite
The expected output of this MWE is two overlaying nodes (i.e. B
and C
).
However, node [draw, right = 1cm of A] (B) {B};
successfully overrides the global setting of node distance=2cm
, while node [draw, right = of A, node distance = 1cm] (C) {C};
doesn't.
So, why do both syntaxes result in different outputs?
documentclass[border=1cm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, right = of A, node distance = 1cm] (C) {C};
end{tikzpicture}
end{document}
tikz-pgf
add a comment |
up vote
6
down vote
favorite
up vote
6
down vote
favorite
The expected output of this MWE is two overlaying nodes (i.e. B
and C
).
However, node [draw, right = 1cm of A] (B) {B};
successfully overrides the global setting of node distance=2cm
, while node [draw, right = of A, node distance = 1cm] (C) {C};
doesn't.
So, why do both syntaxes result in different outputs?
documentclass[border=1cm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, right = of A, node distance = 1cm] (C) {C};
end{tikzpicture}
end{document}
tikz-pgf
The expected output of this MWE is two overlaying nodes (i.e. B
and C
).
However, node [draw, right = 1cm of A] (B) {B};
successfully overrides the global setting of node distance=2cm
, while node [draw, right = of A, node distance = 1cm] (C) {C};
doesn't.
So, why do both syntaxes result in different outputs?
documentclass[border=1cm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, right = of A, node distance = 1cm] (C) {C};
end{tikzpicture}
end{document}
tikz-pgf
tikz-pgf
edited 3 hours ago
asked 19 hours ago
Diaa
2,49311644
2,49311644
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
6
down vote
accepted
The ordering is important. The TikZ parser parses from left to right. This means that you need to first set the node distance (locally) to 1cm by saying node distance = 1cm
, and then let TikZ compute the actual coordinates of the C
node by saying right = of A
.
documentclass[border=1cm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, node distance = 1cm, right = of A] (C) {C};
end{tikzpicture}
end{document}
As you can see, now the B
and C
nodes are on top of each other.
I didn't know my question is that naive
– Diaa
19 hours ago
I really appreciate your answer, but I think it is better to delete this question
– Diaa
19 hours ago
3
@Diaa I do not think your question is naive. Did I misread it? (Actually it took me a while to figure out how that works, and actually you can find some posts by high reputation users on this site who get it wrong IMHO, so I do not think this is a trivial question. But the decision of whether or not to delete is yours.)
– marmot
18 hours ago
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
18 hours ago
@Diaa The question became stupid only after seeing the answer. So please don't delete the question. Instead, downvote for making the question look stupid ;)
– nidhin
15 hours ago
add a comment |
up vote
3
down vote
The operation of the node distance
key is particular and far from obvious. It only works if and only if there is an of part
but no shift part
.
I quote p 231 of 3.0.1a manual:
/tikz/node distance=<shifting part>
(no default, initially 1cm and
1cm) The value of this key is used as is used if and
only if a<of-part>
is present, but no<shifting part>
.
Look at this example.
- Nodes colored blue do not have a
shifting part
in their code, so thenode distance
key is active. - The red colored nodes have a
shifting part
and therefore thenode distance
key is inactive.
documentclass{book}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
foreach i in {8,13,17}{
begin{tikzpicture}[noeud/.style={draw,node distance=i mm},
entre/.style={midway,draw=none,fill=white,inner sep =1pt}]
draw[fill=green!10] (-1,-.1) rectangle (3,5);
draw[help lines] (-1,-.1) grid (3,5);
% No shifting part
begin{scope}[every node/.append style={fill=blue!20,font=scriptsize}]
node[noeud,align=center] (a1) at (0,0) {node distance\ actived};
node[noeud] (b1) [above=of a1] {1};
node[noeud] (c1) [above=of b1] {2};
draw [<->](a1)--(b1)node[entre]{i mm};
draw [<->](b1)--(c1)node[entre]{i mm};
end{scope}
% Shifting part
begin{scope}[every node/.append style={fill=red!20,font=scriptsize}]
node[noeud,align=center] (a2) at (2,0) {node distance\ inactived};
node[noeud] (b2) [above=1cm of a2] {1};
node[noeud] (c2) [above=1cm of b2] {2};
draw [<->](a2)--(b2)node[entre]{1 cm};
draw [<->](b2)--(c2)node[entre]{1 cm};
end{scope}
end{tikzpicture}
}
end{document}
Your code is
right = 1cm of A
The shifting part
is present and equal to 1 cm
. So the key distance node=2cm
is disabled. Point B is therefore located 1 cm from A as you have specified.
Then for point C, you write this:
right = of A, node distance = 1cm
As there is no shifting part
in this code, the distance node=2cm
key is active and therefore the node is placed at 2cm
. Then you specify this distance again, but it has already been computed and so pgf does nothing more, as you can see with a 10 cm distance node key.
documentclass{article}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, right =of A,circle,fill=red!40,opacity=.5,inner sep =10pt] (B) {B};
node [draw, right = of A, node distance = 10cm,fill=blue!40,opacity=.5,inner sep =10pt] (C) {C};
node [draw, node distance = 3cm, right = of A,fill=violet,opacity=.5,inner sep =10pt] (D) {D};
end{tikzpicture}
end{document}
Translated with www.DeepL.com/Translator
1
Many thanks for the comprehensive answer.
– Diaa
15 hours ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
The ordering is important. The TikZ parser parses from left to right. This means that you need to first set the node distance (locally) to 1cm by saying node distance = 1cm
, and then let TikZ compute the actual coordinates of the C
node by saying right = of A
.
documentclass[border=1cm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, node distance = 1cm, right = of A] (C) {C};
end{tikzpicture}
end{document}
As you can see, now the B
and C
nodes are on top of each other.
I didn't know my question is that naive
– Diaa
19 hours ago
I really appreciate your answer, but I think it is better to delete this question
– Diaa
19 hours ago
3
@Diaa I do not think your question is naive. Did I misread it? (Actually it took me a while to figure out how that works, and actually you can find some posts by high reputation users on this site who get it wrong IMHO, so I do not think this is a trivial question. But the decision of whether or not to delete is yours.)
– marmot
18 hours ago
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
18 hours ago
@Diaa The question became stupid only after seeing the answer. So please don't delete the question. Instead, downvote for making the question look stupid ;)
– nidhin
15 hours ago
add a comment |
up vote
6
down vote
accepted
The ordering is important. The TikZ parser parses from left to right. This means that you need to first set the node distance (locally) to 1cm by saying node distance = 1cm
, and then let TikZ compute the actual coordinates of the C
node by saying right = of A
.
documentclass[border=1cm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, node distance = 1cm, right = of A] (C) {C};
end{tikzpicture}
end{document}
As you can see, now the B
and C
nodes are on top of each other.
I didn't know my question is that naive
– Diaa
19 hours ago
I really appreciate your answer, but I think it is better to delete this question
– Diaa
19 hours ago
3
@Diaa I do not think your question is naive. Did I misread it? (Actually it took me a while to figure out how that works, and actually you can find some posts by high reputation users on this site who get it wrong IMHO, so I do not think this is a trivial question. But the decision of whether or not to delete is yours.)
– marmot
18 hours ago
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
18 hours ago
@Diaa The question became stupid only after seeing the answer. So please don't delete the question. Instead, downvote for making the question look stupid ;)
– nidhin
15 hours ago
add a comment |
up vote
6
down vote
accepted
up vote
6
down vote
accepted
The ordering is important. The TikZ parser parses from left to right. This means that you need to first set the node distance (locally) to 1cm by saying node distance = 1cm
, and then let TikZ compute the actual coordinates of the C
node by saying right = of A
.
documentclass[border=1cm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, node distance = 1cm, right = of A] (C) {C};
end{tikzpicture}
end{document}
As you can see, now the B
and C
nodes are on top of each other.
The ordering is important. The TikZ parser parses from left to right. This means that you need to first set the node distance (locally) to 1cm by saying node distance = 1cm
, and then let TikZ compute the actual coordinates of the C
node by saying right = of A
.
documentclass[border=1cm]{standalone}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, node distance = 1cm, right = of A] (C) {C};
end{tikzpicture}
end{document}
As you can see, now the B
and C
nodes are on top of each other.
edited 19 hours ago
answered 19 hours ago
marmot
75.2k485159
75.2k485159
I didn't know my question is that naive
– Diaa
19 hours ago
I really appreciate your answer, but I think it is better to delete this question
– Diaa
19 hours ago
3
@Diaa I do not think your question is naive. Did I misread it? (Actually it took me a while to figure out how that works, and actually you can find some posts by high reputation users on this site who get it wrong IMHO, so I do not think this is a trivial question. But the decision of whether or not to delete is yours.)
– marmot
18 hours ago
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
18 hours ago
@Diaa The question became stupid only after seeing the answer. So please don't delete the question. Instead, downvote for making the question look stupid ;)
– nidhin
15 hours ago
add a comment |
I didn't know my question is that naive
– Diaa
19 hours ago
I really appreciate your answer, but I think it is better to delete this question
– Diaa
19 hours ago
3
@Diaa I do not think your question is naive. Did I misread it? (Actually it took me a while to figure out how that works, and actually you can find some posts by high reputation users on this site who get it wrong IMHO, so I do not think this is a trivial question. But the decision of whether or not to delete is yours.)
– marmot
18 hours ago
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
18 hours ago
@Diaa The question became stupid only after seeing the answer. So please don't delete the question. Instead, downvote for making the question look stupid ;)
– nidhin
15 hours ago
I didn't know my question is that naive
– Diaa
19 hours ago
I didn't know my question is that naive
– Diaa
19 hours ago
I really appreciate your answer, but I think it is better to delete this question
– Diaa
19 hours ago
I really appreciate your answer, but I think it is better to delete this question
– Diaa
19 hours ago
3
3
@Diaa I do not think your question is naive. Did I misread it? (Actually it took me a while to figure out how that works, and actually you can find some posts by high reputation users on this site who get it wrong IMHO, so I do not think this is a trivial question. But the decision of whether or not to delete is yours.)
– marmot
18 hours ago
@Diaa I do not think your question is naive. Did I misread it? (Actually it took me a while to figure out how that works, and actually you can find some posts by high reputation users on this site who get it wrong IMHO, so I do not think this is a trivial question. But the decision of whether or not to delete is yours.)
– marmot
18 hours ago
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
18 hours ago
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
18 hours ago
@Diaa The question became stupid only after seeing the answer. So please don't delete the question. Instead, downvote for making the question look stupid ;)
– nidhin
15 hours ago
@Diaa The question became stupid only after seeing the answer. So please don't delete the question. Instead, downvote for making the question look stupid ;)
– nidhin
15 hours ago
add a comment |
up vote
3
down vote
The operation of the node distance
key is particular and far from obvious. It only works if and only if there is an of part
but no shift part
.
I quote p 231 of 3.0.1a manual:
/tikz/node distance=<shifting part>
(no default, initially 1cm and
1cm) The value of this key is used as is used if and
only if a<of-part>
is present, but no<shifting part>
.
Look at this example.
- Nodes colored blue do not have a
shifting part
in their code, so thenode distance
key is active. - The red colored nodes have a
shifting part
and therefore thenode distance
key is inactive.
documentclass{book}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
foreach i in {8,13,17}{
begin{tikzpicture}[noeud/.style={draw,node distance=i mm},
entre/.style={midway,draw=none,fill=white,inner sep =1pt}]
draw[fill=green!10] (-1,-.1) rectangle (3,5);
draw[help lines] (-1,-.1) grid (3,5);
% No shifting part
begin{scope}[every node/.append style={fill=blue!20,font=scriptsize}]
node[noeud,align=center] (a1) at (0,0) {node distance\ actived};
node[noeud] (b1) [above=of a1] {1};
node[noeud] (c1) [above=of b1] {2};
draw [<->](a1)--(b1)node[entre]{i mm};
draw [<->](b1)--(c1)node[entre]{i mm};
end{scope}
% Shifting part
begin{scope}[every node/.append style={fill=red!20,font=scriptsize}]
node[noeud,align=center] (a2) at (2,0) {node distance\ inactived};
node[noeud] (b2) [above=1cm of a2] {1};
node[noeud] (c2) [above=1cm of b2] {2};
draw [<->](a2)--(b2)node[entre]{1 cm};
draw [<->](b2)--(c2)node[entre]{1 cm};
end{scope}
end{tikzpicture}
}
end{document}
Your code is
right = 1cm of A
The shifting part
is present and equal to 1 cm
. So the key distance node=2cm
is disabled. Point B is therefore located 1 cm from A as you have specified.
Then for point C, you write this:
right = of A, node distance = 1cm
As there is no shifting part
in this code, the distance node=2cm
key is active and therefore the node is placed at 2cm
. Then you specify this distance again, but it has already been computed and so pgf does nothing more, as you can see with a 10 cm distance node key.
documentclass{article}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, right =of A,circle,fill=red!40,opacity=.5,inner sep =10pt] (B) {B};
node [draw, right = of A, node distance = 10cm,fill=blue!40,opacity=.5,inner sep =10pt] (C) {C};
node [draw, node distance = 3cm, right = of A,fill=violet,opacity=.5,inner sep =10pt] (D) {D};
end{tikzpicture}
end{document}
Translated with www.DeepL.com/Translator
1
Many thanks for the comprehensive answer.
– Diaa
15 hours ago
add a comment |
up vote
3
down vote
The operation of the node distance
key is particular and far from obvious. It only works if and only if there is an of part
but no shift part
.
I quote p 231 of 3.0.1a manual:
/tikz/node distance=<shifting part>
(no default, initially 1cm and
1cm) The value of this key is used as is used if and
only if a<of-part>
is present, but no<shifting part>
.
Look at this example.
- Nodes colored blue do not have a
shifting part
in their code, so thenode distance
key is active. - The red colored nodes have a
shifting part
and therefore thenode distance
key is inactive.
documentclass{book}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
foreach i in {8,13,17}{
begin{tikzpicture}[noeud/.style={draw,node distance=i mm},
entre/.style={midway,draw=none,fill=white,inner sep =1pt}]
draw[fill=green!10] (-1,-.1) rectangle (3,5);
draw[help lines] (-1,-.1) grid (3,5);
% No shifting part
begin{scope}[every node/.append style={fill=blue!20,font=scriptsize}]
node[noeud,align=center] (a1) at (0,0) {node distance\ actived};
node[noeud] (b1) [above=of a1] {1};
node[noeud] (c1) [above=of b1] {2};
draw [<->](a1)--(b1)node[entre]{i mm};
draw [<->](b1)--(c1)node[entre]{i mm};
end{scope}
% Shifting part
begin{scope}[every node/.append style={fill=red!20,font=scriptsize}]
node[noeud,align=center] (a2) at (2,0) {node distance\ inactived};
node[noeud] (b2) [above=1cm of a2] {1};
node[noeud] (c2) [above=1cm of b2] {2};
draw [<->](a2)--(b2)node[entre]{1 cm};
draw [<->](b2)--(c2)node[entre]{1 cm};
end{scope}
end{tikzpicture}
}
end{document}
Your code is
right = 1cm of A
The shifting part
is present and equal to 1 cm
. So the key distance node=2cm
is disabled. Point B is therefore located 1 cm from A as you have specified.
Then for point C, you write this:
right = of A, node distance = 1cm
As there is no shifting part
in this code, the distance node=2cm
key is active and therefore the node is placed at 2cm
. Then you specify this distance again, but it has already been computed and so pgf does nothing more, as you can see with a 10 cm distance node key.
documentclass{article}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, right =of A,circle,fill=red!40,opacity=.5,inner sep =10pt] (B) {B};
node [draw, right = of A, node distance = 10cm,fill=blue!40,opacity=.5,inner sep =10pt] (C) {C};
node [draw, node distance = 3cm, right = of A,fill=violet,opacity=.5,inner sep =10pt] (D) {D};
end{tikzpicture}
end{document}
Translated with www.DeepL.com/Translator
1
Many thanks for the comprehensive answer.
– Diaa
15 hours ago
add a comment |
up vote
3
down vote
up vote
3
down vote
The operation of the node distance
key is particular and far from obvious. It only works if and only if there is an of part
but no shift part
.
I quote p 231 of 3.0.1a manual:
/tikz/node distance=<shifting part>
(no default, initially 1cm and
1cm) The value of this key is used as is used if and
only if a<of-part>
is present, but no<shifting part>
.
Look at this example.
- Nodes colored blue do not have a
shifting part
in their code, so thenode distance
key is active. - The red colored nodes have a
shifting part
and therefore thenode distance
key is inactive.
documentclass{book}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
foreach i in {8,13,17}{
begin{tikzpicture}[noeud/.style={draw,node distance=i mm},
entre/.style={midway,draw=none,fill=white,inner sep =1pt}]
draw[fill=green!10] (-1,-.1) rectangle (3,5);
draw[help lines] (-1,-.1) grid (3,5);
% No shifting part
begin{scope}[every node/.append style={fill=blue!20,font=scriptsize}]
node[noeud,align=center] (a1) at (0,0) {node distance\ actived};
node[noeud] (b1) [above=of a1] {1};
node[noeud] (c1) [above=of b1] {2};
draw [<->](a1)--(b1)node[entre]{i mm};
draw [<->](b1)--(c1)node[entre]{i mm};
end{scope}
% Shifting part
begin{scope}[every node/.append style={fill=red!20,font=scriptsize}]
node[noeud,align=center] (a2) at (2,0) {node distance\ inactived};
node[noeud] (b2) [above=1cm of a2] {1};
node[noeud] (c2) [above=1cm of b2] {2};
draw [<->](a2)--(b2)node[entre]{1 cm};
draw [<->](b2)--(c2)node[entre]{1 cm};
end{scope}
end{tikzpicture}
}
end{document}
Your code is
right = 1cm of A
The shifting part
is present and equal to 1 cm
. So the key distance node=2cm
is disabled. Point B is therefore located 1 cm from A as you have specified.
Then for point C, you write this:
right = of A, node distance = 1cm
As there is no shifting part
in this code, the distance node=2cm
key is active and therefore the node is placed at 2cm
. Then you specify this distance again, but it has already been computed and so pgf does nothing more, as you can see with a 10 cm distance node key.
documentclass{article}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, right =of A,circle,fill=red!40,opacity=.5,inner sep =10pt] (B) {B};
node [draw, right = of A, node distance = 10cm,fill=blue!40,opacity=.5,inner sep =10pt] (C) {C};
node [draw, node distance = 3cm, right = of A,fill=violet,opacity=.5,inner sep =10pt] (D) {D};
end{tikzpicture}
end{document}
Translated with www.DeepL.com/Translator
The operation of the node distance
key is particular and far from obvious. It only works if and only if there is an of part
but no shift part
.
I quote p 231 of 3.0.1a manual:
/tikz/node distance=<shifting part>
(no default, initially 1cm and
1cm) The value of this key is used as is used if and
only if a<of-part>
is present, but no<shifting part>
.
Look at this example.
- Nodes colored blue do not have a
shifting part
in their code, so thenode distance
key is active. - The red colored nodes have a
shifting part
and therefore thenode distance
key is inactive.
documentclass{book}
usepackage{tikz}
usetikzlibrary{positioning}
begin{document}
foreach i in {8,13,17}{
begin{tikzpicture}[noeud/.style={draw,node distance=i mm},
entre/.style={midway,draw=none,fill=white,inner sep =1pt}]
draw[fill=green!10] (-1,-.1) rectangle (3,5);
draw[help lines] (-1,-.1) grid (3,5);
% No shifting part
begin{scope}[every node/.append style={fill=blue!20,font=scriptsize}]
node[noeud,align=center] (a1) at (0,0) {node distance\ actived};
node[noeud] (b1) [above=of a1] {1};
node[noeud] (c1) [above=of b1] {2};
draw [<->](a1)--(b1)node[entre]{i mm};
draw [<->](b1)--(c1)node[entre]{i mm};
end{scope}
% Shifting part
begin{scope}[every node/.append style={fill=red!20,font=scriptsize}]
node[noeud,align=center] (a2) at (2,0) {node distance\ inactived};
node[noeud] (b2) [above=1cm of a2] {1};
node[noeud] (c2) [above=1cm of b2] {2};
draw [<->](a2)--(b2)node[entre]{1 cm};
draw [<->](b2)--(c2)node[entre]{1 cm};
end{scope}
end{tikzpicture}
}
end{document}
Your code is
right = 1cm of A
The shifting part
is present and equal to 1 cm
. So the key distance node=2cm
is disabled. Point B is therefore located 1 cm from A as you have specified.
Then for point C, you write this:
right = of A, node distance = 1cm
As there is no shifting part
in this code, the distance node=2cm
key is active and therefore the node is placed at 2cm
. Then you specify this distance again, but it has already been computed and so pgf does nothing more, as you can see with a 10 cm distance node key.
documentclass{article}
usepackage{tikz}
usetikzlibrary{shapes,arrows,positioning}
begin{document}
begin{tikzpicture}[auto, node distance=2cm]
node [draw] (A) {A};
node [draw, right = 1cm of A] (B) {B};
node [draw, right =of A,circle,fill=red!40,opacity=.5,inner sep =10pt] (B) {B};
node [draw, right = of A, node distance = 10cm,fill=blue!40,opacity=.5,inner sep =10pt] (C) {C};
node [draw, node distance = 3cm, right = of A,fill=violet,opacity=.5,inner sep =10pt] (D) {D};
end{tikzpicture}
end{document}
Translated with www.DeepL.com/Translator
edited 15 hours ago
answered 16 hours ago
AndréC
5,6271937
5,6271937
1
Many thanks for the comprehensive answer.
– Diaa
15 hours ago
add a comment |
1
Many thanks for the comprehensive answer.
– Diaa
15 hours ago
1
1
Many thanks for the comprehensive answer.
– Diaa
15 hours ago
Many thanks for the comprehensive answer.
– Diaa
15 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460154%2ftikz-how-does-global-local-node-distance-work%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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