從
\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}