I'm new to TikZ and have a problem with a decision tree. In the example below I would like to have text above the horizontal line of an edge. Something like:
Check
A
|
reject | accept
---------------
| |
Check decision 1
B
When I try to use something like
edge from parent node[above] {accept}
The tree gets totally messed. (example commented out in the code below)
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{trees,positioning,arrows,shapes,backgrounds}
\begin{document}
\begin{tikzpicture}[
% Node style
test/.style={diamond, aspect=2.5,very thick,draw=black,fill=gray!20,text width=1.1cm,
align= center, anchor=north},
dec/.style={rectangle,very thick,draw=black,fill=gray!50,text width=2cm,
text centered, anchor=north},
% Children and edges style
edge from parent/.style={very thick,draw=black},
edge from parent fork down,
level 1/.style={sibling distance=4cm,level distance=2cm}
]
\node (t1) [test] {Check\\A}
child{node (t2) [test] {Check\\B} % edge from parent node[above] {reject}
child{node (t3) [test] {Check\\C}
child{node (t4) [test] {Check\\D}}
child{node (d3) [dec] {decision 3}}
}
child{node (d2) [dec] {decision 2}}
}
child{node (d1) [dec] {decision 1} % edge from parent node[above] {accept}
}
;
\end{tikzpicture}
\end{document}
Then I was wondering also if it is possible to force the horizontal line of the edge to be in the middle between the parent and its children. And if the nodes could be such that their centers have equal height?
center
instead ofnorth
the node centres will line up. Is this what you want?