13

I am trying to build a flow chart using TikZ. I would like the horizontal and vertical spacing to be different. Thus, I am using node distance=2.5cm and 1cm. However, the second distance (1cm) is ignored and the 2.5 cm are used for the horizontal and vertical node distances.

In addition I tried to vary the second value, but still all nodes stay 2.5cm apart.

MWE:

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,shapes,arrows,positioning}
\usetikzlibrary{calc} 
\usepackage[]{xcolor}
\usetikzlibrary{positioning}
\begin{document}

\definecolor{tmp}{RGB}{173, 198, 16}
\tikzstyle{block} = [rectangle, draw, fill=tmp!80, 
    text width=5em, text centered,  minimum height=4em]
\begin{figure}
\small
\begin{tikzpicture}[node distance=2.5cm and 1cm]
    \node [block] (A) {A};
    \node [block,right of=A] (B) {B};
    \node [block,right of=B] (C) {C};
    \node [block,right of=C] (D) {D};
    \node [block,right of=D] (E) {E};
    \node [block,below of=E] (F) {F};
    \node [block,left of=F] (G) {G};
    \node [block,left of=G] (H) {H};
    \node [block,below of=A] (I) {I};
    \node [block,below of=I] (J) {J};
    \node [block,right of=J] (K) {K};
    \node [block,below of=H] (L) {L};
    \node [block,below of=G] (M) {M};

\end{tikzpicture}
\end{figure}
\end{document}

I searched the internet and I believe that I am using the node distance=2.5cm and 1cm correctly. But why doesn't it work?

2

1 Answer 1

17

The difference between right of= and right=of is that the first one uses the center of the node as reference point and the second one uses the border. And with the second one it works.

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,shapes,arrows,positioning}
\usetikzlibrary{calc} 
\usepackage[]{xcolor}
\usetikzlibrary{positioning}
\begin{document}

\definecolor{tmp}{RGB}{173, 198, 16}
\tikzstyle{block} = [rectangle, draw, fill=tmp!80, 
    text width=5em, text centered,  minimum height=4em]
\begin{figure}
\small
\begin{tikzpicture}[node distance=3cm and 1cm,auto]
    \node [block] (A) {A};
    \node [block,right= of A] (B) {B};
    \node [block,right= of B] (C) {C};
    \node [block,right= of C] (D) {D};
    \node [block,right= of D] (E) {E};
    \node [block,below= of E] (F) {F};
    \node [block,left= of F] (G) {G};
    \node [block,left= of G] (H) {H};
    \node [block,below= of A] (I) {I};
    \node [block,below= of I] (J) {J};
    \node [block,right= of J] (K) {K};
    \node [block,below= of H] (L) {L};
    \node [block,below= of G] (M) {M};

\end{tikzpicture}
\end{figure}
\end{document}

Edit: For further information see the link in the second comment of the question.

1
  • 1
    Just to add, it's essential to add tikz library positioning for this to work... (you do it twice even!)
    – JHBonarius
    Commented Mar 15, 2018 at 12:24

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