Как правильно отобразить дерево AVL в LaTex?Соло левый ребенок висит прямо вниз - PullRequest
4 голосов
/ 16 марта 2010

Приведенный ниже код почти идеально работает, однако ребенок 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}}

Спасибо, CB

Ответы [ 2 ]

6 голосов
/ 16 марта 2010

Код ниже работает для меня.Он основан на вашем коде, с изменениями

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}
2 голосов
/ 17 марта 2010

После консультации с руководством по 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}
...