Como posso exibir corretamente minha árvore AVL no látex? Uma criança esquerda solo fica direto para baixo

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

  •  20-09-2019
  •  | 
  •  

Pergunta

O código abaixo quase funciona perfeitamente, no entanto, o filho de 9, 7, fica direto para baixo, em vez de como filho esquerdo. Como posso corrigir isso?

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

Obrigado, cb.

Foi útil?

Solução 2

Depois de consultar o manual do Tikz, como sugerido, pude corrigir isso da seguinte maneira.

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

Outras dicas

O código abaixo funciona para mim. É baseado no seu código, com as alterações

1) Use as árvores da biblioteca Tikz e 2) mudança da formatação de um único nó (nó 7)

Para mais informações, consulte o Manual 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}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top