正确的语法“right= of”不会改变“节点距离”

正确的语法“right= of”不会改变“节点距离”

我一直试图将一个节点定位在另一个节点的右边。

我正在使用定位库。它工作正常:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[draw] (a) at (0,0){First};
\node[draw,above right =of a,node distance=200 and 100] (b){second};
\end{tikzpicture}
\end{document}

这不是:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[draw] (a) at (0,0){First};
\node[draw,right =of a,node distance=200] (b){second};% correct syntax but does not shift
\node[draw,right of = a,node distance=200] (c){third};%wrong syntax but shifts
\node[draw,right =of a,node distance=400 and 400] (d){fourth};% also does not shift
\end{tikzpicture}
\end{document}

有人能告诉我我做错了什么吗?我只想要“第一个”节点右侧的“第二个”节点。

答案1

说起来容易做起来难

<position> = <node distance> of <othernode>

例如

\node [draw,right=4cm of a] {second};
\node [draw,above right=2cm and 4cm of a] {third};

但至于为什么你的代码不起作用,顺序似乎很重要。设置node distance 您设置了相对位置。

代码输出

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[node distance=1cm]
\node[draw] (a) {First};
\node[draw,right=of a]                    (b) {second};
\node[draw,node distance=4cm, right=of a] (c) {third};
\end{tikzpicture}
\end{document}

相关内容