在tikz中設定邊界之間的節點距離

在tikz中設定邊界之間的節點距離

\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之間的距離短。AB

答案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}

在此輸入影像描述

相關內容