# Tikz, childs not exactly on the same level

I'm having trouble arranging my child nodes. They don't seem to be centered, horizontally, if use the anchor=north setting. It looks like they are arrange according to their top edge of the node, but i would like to have them centered, so that the connection between the childs a parallel. I'll hope you understand what I mean!

\begin{tikzpicture}[->,>=stealth',
edge from parent/.style={thick,draw=black!70,-latex},
level 1/.style={sibling distance=4cm},
,level distance =4.5cm,auto,scale=0.75,transform shape]

\tikzstyle{and}=[rectangle, rounded corners,thick,draw=black!75,top color=blue!10, bottom color=white,minimum size=5mm]
\tikzstyle{or}=[rectangle,rounded corners,thick,draw=black!75,top color=red!10, bottom color=white,minimum size=5mm]
\tikzstyle{terminal}=[rectangle, rounded corners, thick,draw=black!75, top color=green!5, bottom color=white,minimum size=5mm]
\tikzstyle{relation}=[rectangle,rounded corners,inner sep=2pt, thick,draw=black!75, top color=gray!20, bottom color=white,minimum size=5mm, font =\scriptsize]

\node [or,right=6.75cm of obstacle] (obstacle1)  {\begin{tabular}{l} Obstacle at \\ zebra crossing \end{tabular}}
child{ [sibling distance = 8cm]  node [and,anchor=north] (ped_on_zebra) {\begin{tabular}{l} Pedestrian \\ on zebra crossing \end{tabular}}
child{ node [terminal,anchor=north] (ped1) {Pedestrian} }
child{ node [relation,anchor=north] (rel_11) {\begin{tabular}{l} dist., \\ vel. \\ orient.\end{tabular}}  }
child{  node [terminal,anchor=north] (zebra_21) {\begin{tabular}{l} Zebra \\ crossing \end{tabular}}  }  }
;
\path
(rel_11) edge node [left] {} (ped1)
(rel_11) edge node [right] {} (zebra_21);

\end{tikzpicture}

• Well, then don’t use the option anchor=north but anchor=center (which is the default). This positions the children at the same height. – Qrrbrbirlbel Jul 9 '13 at 11:12
• The problem is, that I want to have the anchor at north. Is there another possibility? – Stefan Jul 9 '13 at 11:28
• Actually I saw your comment in my other question, now i don't have to use anchor=north ;-), Thanks! – Stefan Jul 9 '13 at 11:37
• Hi Stefan, and welcome to the site. I'm having a bit of trouble recreating your situation on my machine. Could you turn your code snippet into a compilable .tex file, starting with \documentclass and ending with \end{document}? – John Wickerson Jul 9 '13 at 12:40

If you want to use anchor=north for terminal nodes and connect them with an horizontal line you have two options:

1- Make all terminal and relation nodes have same height with a minimum height large enough. This way, they will be aligned according north anchor but also their center.

2- Don't touch terminal and relation nodes height but draw an horizontal line between them which it's different from a line between their centers. I think it's not so nice but possible:

\path
(rel_11.west|-ped1) edge node [left] {} (ped1)
(rel_11.east|-ped1) edge node [right] {} (zebra_21.west|-ped1);


Red line is drawn between centers and green line is drawn with previous command.

Next code is a modified version of your one. What's different?

1- All styles are defined inside [...] after \begin{tikzpicture} and avoiding \tikzstyle

2- All your nodes share same options except top color, so you can declare a general style (mynode) with one argument and use it to define terminal, relation, ... styles.

3- mynode includes options text width and align which allow to avoid using tabular inside node's text. You can still use \\ to break lines or left LaTeX to do it for you.

4- I've suppressed node [left] {} from edge path because they are superfluous in this figure.

5- I've suppressed ,right=6.75cm of obstacle because there is no obstacle node in this example.

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,positioning}
\begin{document}

\begin{tikzpicture}[->,>=stealth',
edge from parent/.style={thick,draw=black!70,-latex},
level 1/.style = {sibling distance=4cm},
level distance = 4.5cm,auto,scale=0.75,transform shape,
mynode/.style = {rectangle, rounded corners, thick, minimum size = 5mm, text width = 3cm, align = center, draw=black!75, bottom color=white, top color=#1},
and/.style = {mynode=blue!10},
or/.style = {mynode=red!10},
terminal/.style = {mynode=green!10},
relation/.style = {mynode=gray!10, font=\scriptsize},
]

\node [or] (obstacle1)  {Obstacle at \\ zebra crossing}
child{ [sibling distance = 8cm]  node [and,anchor=north] (ped_on_zebra) {Pedestrian \\ on zebra crossing}
child{ node [terminal,anchor=north] (ped1) {Pedestrian} }
child{ node [relation,anchor=north] (rel_11) {dist., \\ vel. \\ orient.}  }
child{  node [terminal,anchor=north] (zebra_21) {Zebra \\ crossing}  }  }
;
\path[red]
(rel_11) edge (ped1)
(rel_11) edge (zebra_21);
\path[green]
(rel_11.west|-ped1) edge (ped1)
(rel_11.east|-ped1) edge (zebra_21.west|-ped1);

\end{tikzpicture}

\end{document}