[Tex/LaTex] Set node distance between borders in tikz

blocknodespositioningtikz-pgf

From

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

I get this figure

enter image description here

How can I set the distance between the nodes' borders rather than their centers?

In the figure the distance between B and loooooooooooooooong C is shorter than the distance between A and B.

Best Answer

You have to use right = of (which is the syntax for positioning library) instead of 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}

enter image description here