Как я могу правильно отобразить мое AVL-дерево в LaTeX?Сольный левый ребенок висит прямо вниз
Вопрос
Приведенный ниже код почти работает идеально, однако дочерний элемент 9, 7, висит прямо вниз, а не как левый дочерний элемент.Как я могу это исправить?
\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}}
Спасибо, КБ
Решение 2
Проконсультировавшись с руководством tikz, как было предложено, я смог исправить это следующим образом.
\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}
Другие советы
Приведенный ниже код работает для меня.Он основан на вашем коде, с изменениями
1) использовать деревья библиотеки tikz и 2) изменить форматирование одного узла (узел 7)
Для получения дополнительной информации смотрите руководство 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}
Не связан с StackOverflow