3

I'm writing a Java app to generate tries for Latex using TikZ.

I'm struggling to typeset a Trie to follow example below:

example

Could someone provide me with an example how to properly nest children nodes and corresponding labels.

What I got now is:

\begin{tikzpicture}
\node [circle] {}
    child{ node [circle] {} edge from parent node[above left] {$B$} }
    child{ node [circle] {} edge from parent node[above left] {$F$}
            child [circle] {}
        }; 
\end{tikzpicture}

But edge labels won't match to the right edges.

5

Actually, there are a number of questions with answers which label edges...

This might give you some ideas:

\documentclass[tikz]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
  circle,
  black,
  draw,
  fill=blue!40,
}
  [{}
    [{}, edge label={node [midway, above left] {B}}
      [{}, edge label={node [midway, right] {A}}
        [{}, edge label={node [midway, right] {U}}
          [,phantom]
          [{}, edge label={node [midway, left] {E}}
            [{}, edge label={node [midway, left] {R}}, label=below:Bauer
            ]
            [,phantom]
          ]
          [{}, edge label={node [midway, right] {M}}, label=below:Baum
          ]
          [,phantom]
        ]
        [,phantom]
      ]
      [,phantom]
    ]
    [{}, edge label={node [midway, right] {F}}
      [{}, edge label={node [midway, right] {E}}
        [{}, edge label={node [midway, right] {L}}
          [{}, edge label={node [midway, right] {D}}, label=below:Feld
          ]
          [,phantom]
        ]
        [,phantom]
      ]
      [,phantom]
    ]
    [{}, edge label={node [midway, left] {H}}
      [{}, edge label={node [midway, left] {A}}
        [{}, edge label={node [midway, left] {H}}
          [{}, edge label={node [midway, left] {N}}, label=below:Hahn
          ]
          [,phantom]
        ]
        [{}, edge label={node [midway, right] {U}}
          [{}, edge label={node [midway, left] {S}}, label=below:Haus
          ]
          [,phantom]
        ]
        [,phantom]
      ]
      [{}, edge label={node [midway, left] {O}}
        [{}, edge label={node [midway, right] {F}}, label=below:Hof
        ]
      ]
      [{}, edge label={node [midway, right] {U}}
        [,phantom]
        [{}, edge label={node [midway, left] {H}}
          [{}, edge label={node [midway, right] {N}}, label=below:Huhn
          ]
        ]
        [{}, edge label={node [midway, right] {N}}
          [,phantom]
          [{}, edge label={node [midway, right] {D}}, label=below:Hund
          ]
        ]
      ]
    ]
    [{}, edge label={node [midway, above right] {K}}
      [,phantom]
      [{}, edge label={node [midway, right] {A}}
        [,phantom]
        [{}, edge label={node [midway, right] {T}}
          [,phantom]
          [{}, edge label={node [midway, right] {Z}}
            [,phantom]
            [{}, edge label={node [midway, right] {E}}, label=below:Katze
            ]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\end{document}

Forest tree

  • 1
    So you typed! +1 for that :) – user11232 Jun 1 '14 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.