在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}

在此处输入图片描述

相关内容