¿Cómo puedo visualizar correctamente mi árbol AVL en el látex? Un niño-izquierda en solitario cuelga hacia abajo

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

  •  20-09-2019
  •  | 
  •  

Pregunta

El código de abajo casi funciona a la perfección, sin embargo, el niño de 9, 7, cuelga hacia abajo en lugar de como un hijo izquierdo. ¿Cómo puedo corregir esto?

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

Gracias, CB

¿Fue útil?

Solución 2

Después de consultar con el manual TikZ como se sugiere, yo era capaz de corregir esto de la siguiente manera.

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

Otros consejos

El siguiente código funciona para mí. Se basa en el código, con los cambios

1) utilizar los árboles de la biblioteca y TikZ 2) el cambio del formato de un solo nodo (nodo 7)

Para obtener más información, consulte el manual de 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 bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top