10

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.

1

1 Answer 1

7

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

2
  • This doesn't make any difference for me for some reason. Either right=of or right of= use node centers. Apr 16, 2021 at 19:15
  • Ah I found the problem -- the on grid option if set for nodes messes this up. Apr 16, 2021 at 19:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .