从
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{shapes,arrows,positioning}
\begin{document}
\tikzstyle{block} = [draw, rectangle, minimum height=3em, minimum width=6em]
\tikzstyle{line} = [->, dashed]
\begin{tikzpicture}[auto, node distance=3.5cm,>=latex']
\node [block] (A) {A};
\node [block,right of=A] (B) {B};
\node [block,right of=B] (C) {loooooooooooooooong C};
\node [block,right of=C] (D) {D};
\draw [line] (A) -- (B);
\draw [line] (B) -- (C);
\draw [line] (C) -- (D);
\end{tikzpicture}
\end{document}
我得到这个数字
如何设置节点边界而不是中心之间的距离?
图中B
和之间的距离比和loooooooooooooooong C
之间的距离短。A
B
答案1
您必须使用right = of
(这是库的语法positioning
)而不是right of =
。
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{shapes,arrows,positioning}
\begin{document}
\tikzstyle{block} = [draw, rectangle, minimum height=3em, minimum width=6em]
\tikzstyle{line} = [->, dashed]
\begin{tikzpicture}[auto, node distance=3.5cm,>=latex']
\node [block] (A) {A};
\node [block,right = of A] (B) {B};
\node [block,right = of B] (C) {loooooooooooooooong C};
\node [block,right = of C] (D) {D};
\draw [line] (A) -- (B);
\draw [line] (B) -- (C);
\draw [line] (C) -- (D);
\end{tikzpicture}
\end{document}