# Tikz Tree problem with position

I have a problem with my Tikz Tree. The right edge that connects the node "NON Mammifero" in the first level, goes down at the same level of edge label "NO".

I would like it to stop at the first level with the node "Partorisce". I try to use sibling distance and level distance, but (i don't know why) doesn't work.

Here the library:

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}


Here the code:

\begin{figure}[htbp]
\centering
\begin{tikzpicture}[sibling distance=5cm,  level distance=3cm,
every node/.style = {
align=center,
top color=white }]
\node[ellipse][draw]{Termofisiologia}
child { edge from parent node[above left,pos=.3]{Sangue-caldo} node[ellipse,draw] {Partorisce}
child { node[draw] {Mammifero}  edge from parent node[above left]{SI}}
child { node[draw] {NON Mammifero}  edge from parent node[above right]{NO}} }
child { node[draw] {NON Mammifero} edge from parent node[above right]{Sangue-freddo} };

\end{tikzpicture}
\vspace{0.2cm}
\caption{Esempio di albero decisionale}

• please, always provide complete small document (called minimal working example: mwe) which show your problem and which we can copy and test. now we need to write it from your code segments. this is very disturbing in help to you. please, help us to help you! – Zarko Dec 21 '17 at 10:40

Seems you need to move edge from parent node[..] {Sangue-caldo} to after the children of the Partorisce node.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}[
sibling distance=5cm,
level distance=3cm,
every node/.style = {
align=center,
top color=white
}
]
\node[ellipse][draw]{Termofisiologia}
child {
node[ellipse,draw] {Partorisce}
child {
node[draw] {Mammifero}
edge from parent node[above left]{SI}
}
child {
node[draw] {NON Mammifero}
edge from parent node[above right]{NO}
}
edge from parent node[above left] {Sangue-caldo} % this is moved to after the children of the node
}
child {
node[draw] {NON Mammifero}
edge from parent node[above right]{Sangue-freddo}
};

\end{tikzpicture}
\caption{Esempio di albero decisionale}
\end{figure}
\end{document}


For the heck of it, here's a forest alternative, borrowing a bit from cfr's answer to Drawing a game tree on Tikz forest is designed specifically for drawing trees.

\documentclass{article}
\usepackage{forest}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{figure}[htbp]
\centering

\begin{forest}
for tree={
l sep'+=25pt,
s sep'+=5pt,
},
Rect/.style={
draw,
if={isodd(n)}%
{edge label={node[auto,left,midway]{#1}}}%
{edge label={node[auto,right,midway]{#1}}}
},
Ell/.style={
Rect={#1},
ellipse
},
Rect/.default={},
Ell/.default={}
%
[Termofisiologia, Ell
[Partorisce, Ell={Sangue-caldo}
[Mammifero, Rect={NO}]
[NON Mammifero, Rect={SI}]
]
[NON Mammifero, Rect={Sangue-freddo}]
]
\end{forest}
\caption{Esempio di albero decisionale}
\end{figure}
\end{document}

• I like the use of .default. I didn't know you could do that with Forest styles, although, now I've seen you do it, I can't see why not :-). – cfr Dec 21 '17 at 16:56
• @cfr I didn’t know either, but they started out as TikZ styles with a default, so I just tried moving them over, and it worked. – Torbjørn T. Dec 21 '17 at 17:03

Here is another solution using the istgame package:

\documentclass{article}

\usepackage{istgame}

\begin{document}

\begin{figure}[htbp]
\begin{istgame}%[font=\scriptsize]
\xtdistance{30mm}{50mm}
\istrooto(0){Termofisiologia}
\istb{\mbox{Sangue-caldo}}[al]
\istb{\mbox{Snague-freddo}}[ar]
\endist
\istrooto(1)(0-1){Partorisce}
\istb{\mbox{SI}}[al]
\istb{\mbox{NO}}[ar]
\endist
\istrooto(2)(0-2)[box node]{NON Mammifero}
\endist
\istrooto(3)(1-1)[box node]{Mammifero}
\endist
\istrooto(4)(1-2)[box node]{NON Mammifero}
\endist
\end{istgame}
\caption{Esempio di albero descisionale}
\end{figure}

\end{document}