Comment puis-je afficher correctement mon arbre AVL en LaTex? Un enfant laissé seul pend vers le bas

StackOverflow https://stackoverflow.com/questions/2454526

  •  20-09-2019
  •  | 
  •  

Question

Le code ci-dessous fonctionne presque parfaitement, mais l'enfant de 9, 7, pend vers le bas au lieu d'un enfant gauche. Comment puis-je corriger?

\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}}

Merci, CB

Était-ce utile?

La solution 2

Après avoir consulté le manuel tikz comme le suggère, j'ai pu corriger comme suit.

\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}

Autres conseils

Le code ci-dessous fonctionne pour moi. Il est basé sur votre code, avec les modifications

1) utiliser les arbres de la bibliothèque et tikz 2) le changement de la mise en forme d'un seul noeud (noeud 7)

Pour plus d'informations, consultez le manuel 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}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top