TikZ: How does global/local [node distance] work?
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 |
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 |
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 Nov 16 at 7:43
asked Nov 15 at 15:58
Diaa
2,65911747
2,65911747
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
Nov 15 at 16:07
I really appreciate your answer, but I think it is better to delete this question
– Diaa
Nov 15 at 16:08
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
Nov 15 at 16:09
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
Nov 15 at 16:10
@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
Nov 15 at 19:34
add a comment |
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
Nov 15 at 20:00
add a comment |
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
});
}
});
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
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
Nov 15 at 16:07
I really appreciate your answer, but I think it is better to delete this question
– Diaa
Nov 15 at 16:08
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
Nov 15 at 16:09
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
Nov 15 at 16:10
@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
Nov 15 at 19:34
add a comment |
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
Nov 15 at 16:07
I really appreciate your answer, but I think it is better to delete this question
– Diaa
Nov 15 at 16:08
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
Nov 15 at 16:09
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
Nov 15 at 16:10
@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
Nov 15 at 19:34
add a comment |
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 Nov 15 at 16:08
answered Nov 15 at 16:06
marmot
86.3k499184
86.3k499184
I didn't know my question is that naive
– Diaa
Nov 15 at 16:07
I really appreciate your answer, but I think it is better to delete this question
– Diaa
Nov 15 at 16:08
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
Nov 15 at 16:09
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
Nov 15 at 16:10
@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
Nov 15 at 19:34
add a comment |
I didn't know my question is that naive
– Diaa
Nov 15 at 16:07
I really appreciate your answer, but I think it is better to delete this question
– Diaa
Nov 15 at 16:08
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
Nov 15 at 16:09
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
Nov 15 at 16:10
@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
Nov 15 at 19:34
I didn't know my question is that naive
– Diaa
Nov 15 at 16:07
I didn't know my question is that naive
– Diaa
Nov 15 at 16:07
I really appreciate your answer, but I think it is better to delete this question
– Diaa
Nov 15 at 16:08
I really appreciate your answer, but I think it is better to delete this question
– Diaa
Nov 15 at 16:08
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
Nov 15 at 16:09
@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
Nov 15 at 16:09
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
Nov 15 at 16:10
I mean it is a stupid question XD that doesn't deserve to be asked :)
– Diaa
Nov 15 at 16:10
@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
Nov 15 at 19:34
@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
Nov 15 at 19:34
add a comment |
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
Nov 15 at 20:00
add a comment |
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
Nov 15 at 20:00
add a comment |
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 Nov 15 at 19:15
answered Nov 15 at 18:16
AndréC
7,54911440
7,54911440
1
Many thanks for the comprehensive answer.
– Diaa
Nov 15 at 20:00
add a comment |
1
Many thanks for the comprehensive answer.
– Diaa
Nov 15 at 20:00
1
1
Many thanks for the comprehensive answer.
– Diaa
Nov 15 at 20:00
Many thanks for the comprehensive answer.
– Diaa
Nov 15 at 20:00
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
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