Come posso mostrare il mio modo corretto AVL Albero in LaTex? Un assolo di sinistra-bambino pende verso il basso
Domanda
Il codice sotto quasi funziona perfettamente, ma il figlio di 9, 7, pende verso il basso anziché come sinistra-figlio. Come posso correggere questo?
\usepackage{tikz}
\usepackage{xytree}
\begin{tikzpicture}[level/.style={sibling distance=60mm/#1}]
\node [circle,draw] {4}
child {
node [circle,draw] {2}
child {node [circle,draw] {1}
}
child {
node [circle,draw]{3}
}
}
child {node [circle,draw] {6}
child {node [circle,draw] {5}
}
child {node [circle,draw] {9}
child {node [circle, draw] {7}}
}
};
\end{tikzpicture}}
Grazie, CB
Soluzione 2
Dopo aver consultato il manuale di tikz come suggerito, ero in grado di correggere questo come segue.
\begin{tikzpicture}[level/.style={sibling distance=60mm/#1}]
\node [circle,draw] {4}
child {
node [circle,draw] {2}
child {node [circle,draw] {1}
}
child {
node [circle,draw]{3}
}
}
child {node [circle,draw] {6}
child {node [circle,draw] {5}
}
child {node [circle,draw] {9}
child {node [circle, draw] {7}}
child [missing]
}
};
\end{tikzpicture}
Altri suggerimenti
Il seguente codice funziona per me. Si basa sul codice, con le modifiche
1) utilizzare gli alberi biblioteca tikz e 2) modifica della formattazione di un singolo nodo (nodo 7)
Per ulteriori informazioni consultare il manuale di tikz
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\begin{tikzpicture}[level/.style={sibling distance=60mm/#1}]
\node [circle,draw] {4}
child {
node [circle,draw] {2}
child {node [circle,draw] {1}
}
child {
node [circle,draw]{3}
}
}
child {node [circle,draw] {6}
child {node [circle,draw] {5}
}
child {node [circle,draw] {9}
child[grow via three points={one child at (-1,-1) and two children at (-.5,1) and (.5,1)}] {node [circle, draw] {7}}
}
};
\end{tikzpicture}
\end{document}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow