1

I'm completely new to latex and I'm currently trying to create a flow of inserting nodes into a tree. I'm having a problem with the lines on my trees as they become straight for some of them, does anyone know how to fix this?

\begin{minipage}{0.1\textwidth}
 \centering

\begin{tikzpicture}[ edge from parent path= {(\tikzparentnode.south) .. controls +(0,-.5) and +(0,.5) .. (\tikzchildnode.north)}, every node/.style={draw,circle, label distance=-2mm}, level distance=20mm ] \node [label=330:$0$]{5}; \end{tikzpicture} \end{minipage}% \begin{minipage}{0.02\textwidth} \centering $\rightarrow$ \end{minipage}% \begin{minipage}{0.1\textwidth} \centering

\begin{tikzpicture}[ edge from parent path= {(\tikzparentnode.south) .. controls +(0,-.5) and +(0,.5) .. (\tikzchildnode.north)}, every node/.style={draw,circle, label distance=-2mm}, level distance=20mm ] \node [label=330:$1$]{5} child {node[label=330:$0$] {4}}; \end{tikzpicture} \end{minipage}%

Latex Image

David Carlisle
  • 757,742
YoshiW
  • 13

1 Answers1

0

Edit:

An example of AVL tree (as presented in wikipedia):

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}

\begin{document} \begin{tikzpicture}[ C/.style = {draw, circle, minimum size=1.5em, inner sep=0pt, label={[font=\scriptsize, text=blue, inner sep=0pt]330:$#1$}}, ] \node [C=-1] {5} child {node[C=1] {5}} child {node[C=0] {4}} ; \end{tikzpicture} \end{document}

enter image description here

or as evolution of two trees drawn with pure \tikz and use positioning library (arrows.meta is only for nice looking arrows heads):

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning}

\begin{document}

\begin{tikzpicture}[ node distance = 7mm and 21mm, C/.style = {draw, circle, minimum size=1.5em, inner sep=0pt, label={[font=\scriptsize, text=blue, inner sep=0pt]330:$#1$}}, ] \node (n1)[C=-1] {5}; \node (n21) [C=1, above right=of n1] {5}; \node (n22) [C=0, below right=of n1] {4}; \draw (n21) -- (n22); \draw[-Straight Barb,shorten <=7mm, shorten >=7mm] (n1) -- (n1 -| n21); \end{tikzpicture}

\end{document}

enter image description here

Zarko
  • 296,517