# Node placement distance problem, relative positioning

Is it possible to specify the distance between the nodes using the relative positioning (such as below of) so this doesn't happen:

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.multipart}
\usepackage{flowchart}
\usetikzlibrary{positioning}
\begin{document}
\pagestyle{empty}

\tikzstyle{decision_lb} = [diamond, draw, fill = blue!20,
text badly centered, node distance=3cm, text width = ]
% Operation
\tikzstyle{c_op} = [rectangle, draw, fill = blue!20,
text centered, minimum height=4em,  text width=,minimum size=2em]

\begin{tikzpicture}[node distance = 1.5cm, auto]
\node[decision_lb](dec1){veeeery looooooooooooooooonnnnnnnnnnnnnnnnnggggggggggggggg text};
%yes branch
\node[c_op, below of = dec1] (op4) {$formulas$};

\end{tikzpicture}

\end{document}


This is, of course, a overexaggerated example but I have the same problem in a more complicated figure.

I need some command similar to below of but it has to include the outside measures of the previous shape. I'm using no yshift but it is trial and error to find the right value to make it look good. Until now I also wasn't able to find a similar question.

Edit: I want to place op4 in the same distance as in the second example regardless of what is written in dec1.

Second example:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.multipart}
\usepackage{flowchart}
\usetikzlibrary{positioning}
\begin{document}
\pagestyle{empty}

\tikzstyle{decision_lb} = [diamond, draw, fill = blue!20,
text badly centered, node distance=3cm, text width = ]
% Operation
\tikzstyle{c_op} = [rectangle, draw, fill = blue!20,
text centered, minimum height=4em,  text width=,minimum size=2em]

\begin{tikzpicture}[node distance = 1.5cm, auto]
\node[c_op](dec1){veeeery looooooooooooooooonnnnnnnnnnnnnnnnnggggggggggggggg text};
%yes branch
\node[c_op, below of = dec1] (op4) {$formulas$};
\end{tikzpicture}

\end{document}


Edit2: I want the same vertical distance between my shapes. My problem is that below of = dec1 just specifies the distances between the node origins. If the text in the shape diamond gets very long the diamond gets also vertically very big, but the distance to the next shape below is not changed (cause the node origins stay the same). So I need a command that specifies the distances to the outside of the other shape.

• – Torbjørn T. Sep 19 '17 at 18:14
• You can use a node: decision_lb with the text as \phantom{text} and then use just simple nodes at dec1 and [below of=dec1]. – koleygr Sep 19 '17 at 18:28
• i told you in my answer, that you use wrong syntax for distances. please read my answer again. – Zarko Sep 19 '17 at 19:07

i guess that you like to obtain something like this:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, positioning, shapes}

\begin{document}

\begin{tikzpicture}[auto,
node distance = 11mm and 22mm,
decision_lb/.style = {diamond, draw, fill = blue!20,
text width=4.5em, align=flush center},
c_op/.style = {rectangle, draw, fill = blue!20,
text width=5em, align=center, minimum height=4em}
]
\node (dec1) [decision_lb]          {very long text};
%yes branch
\node (op4)  [c_op, below=of dec1]  {$formulas$};

\end{tikzpicture}

\end{document}


in above mwe i do the following:

• replace depreciated \tikzstyle with options of tikzpicture. you also can move those options to \tikzset{...}
• clean up styles definitions from repeating text width ...
• reduce inner sep to default value
• use syntax defined by positioning package: below=of ... and not below of= ...

addendum (1): tell me, if now i understand you correct: you like to have the next node width the same width as previous one, i.e.: the rectangle below diamond should be the same of width as diamond?

if my guessing is (this time) correct than one of possible solution is:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, positioning, shapes}

\begin{document}

\begin{tikzpicture}[auto,
node distance = 11mm and 22mm,
decision_lb/.style = {diamond, draw, fill = blue!20,
align=flush center},
c_op/.style = {rectangle, draw, fill = blue!20,
text width=#1 - 2*\pgfkeysvalueof{/pgf/inner xsep},
align=center, minimum size=4em},
]
\node (dec1) [decision_lb]  {very long text};
%yes branch
\path   let \p1 = ($(dec1.west)-(dec1.east)$),
\n1 = {veclen(\y1,\x1)} in
node (op4) [c_op=\n1, below=of dec1]  {$formulas$};

\end{tikzpicture}

\end{document}


which gives:

addendum (2): as follows from last edit of question, you problem is use of wrong syntax for node distance. for correct one see last item in above list. let repeat me:

wrong: below of = dec1

correct: below = of dec1

for demonstrate this let me extend the first answer to more nodes:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, positioning, shapes}

\begin{document}

\begin{tikzpicture}[auto,
node distance = 4mm and 8mm,
decision_lb/.style = {diamond, draw, fill = blue!20,
text width=4.5em, align=flush center},
c_op/.style = {rectangle, draw, fill = blue!20,
minimum width=5em,
align=center, minimum height=4em},
]
\node (dec1) [decision_lb]  {very long text};
%yes branch
\node (op4) [c_op, below=of dec1]  {$formulas$}; % <-- observe syntax for distance between nodes
\node (op5) [c_op, below=of op4]   {$formulas$}; % <-- observe syntax for distance between nodes
\end{tikzpicture}

\end{document}


as you can see, distances between nodes are equal.

• Thank you. It's not exactly what i wanted but i guess it wasn't clear enough. But it still could help me. I have one question. How can i achieve that the 'below= of' makes the same distances as the 'below of='? – Michael Obermeist Sep 19 '17 at 17:15
• @MichaelObermeist, please explain what is not what you like to have. the best way is edit your question and (hand drawing) add sketch, what you like to have. – Zarko Sep 19 '17 at 17:18
• i edited the question. Please let me know if it's still not clear. – Michael Obermeist Sep 19 '17 at 18:08
• sorry, still have problems. see addendum to my answer, if my "crystal ball" works better :-) – Zarko Sep 19 '17 at 18:25
• Thank you. no problem =) i wrote another edit ;) – Michael Obermeist Sep 19 '17 at 18:55

You could also use a matrix and let tikz work for you:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, positioning, shapes, matrix}

\begin{document}

\begin{tikzpicture}[
decision_lb/.style = {diamond, draw, fill = blue!20,
text width=4.5em, align=flush center},
c_op/.style = {rectangle, draw, fill = blue!20,
minimum width=5em,
align=center, minimum height=4em},
]
\matrix[matrix of nodes,
row sep=1.5cm, column sep=1.5cm]{
|[decision_lb, name=dec1]| {very long text}
& |[c_op, name= dec2]| {veeeery
looooooooooooooooonnnnnnnnnnnnnnnnnggggggggggggggg text}\\
|[c_op, name= op4]| {$formulas$}
& |[c_op, name= op5]| {$formulas$} \\
};
\end{tikzpicture}
\end{document}


• Thank you this looks interesting. I didn't try \matrix until now. Can i set coordinates for path's also instead of nodes? – Michael Obermeist Sep 20 '17 at 14:15
• @MichaelObermeist It's more or less like a tabular, I think it is very useful for node positioning :) – CarLaTeX Sep 20 '17 at 14:17