0

I know how to draw a $k$-tree of just single level, but I also need the grouping of the edges. See the diagram below:

enter image description here

This is what I am trying:

\begin{forest}
for tree={l+=0.08cm} % increase level distance
  [1
    [2
       [4][5]
    ]
    [3
       [6][7]
    ]
  ]
\end{forest}
2

Here is an example with a few braces. The way the endpoints of the brace is defined is called a "nodewalk" I think. I probably can't explain it better than the forest manual, so read the example that starts at the bottom of page 8, starting with "Finally, the most powerful tool", and also 3.8.7 on page 57. (Page references are given based on the manual to version 2.1.5 of forest, dated July 14 2017.)

output of code

\documentclass[border=5mm]{standalone}
\usepackage{forest}
\usetikzlibrary{decorations.pathreplacing}
\tikzset{
  Brace/.style={
      decoration={
         brace,
         mirror,
         amplitude=5pt,
         raise=#1 % use argument to style to determine how far the brace is moved
      },
      decorate
  },
  % set the default argument to 0
  Brace/.default=0
}
\begin{document}
\begin{forest}
for tree={l+=0.08cm} % increase level distance
  [1
    [2
       [4]
       {
          \draw [Brace] (.south west) -- (!>>>>.south east);
          \draw [red,Brace=5pt] (.south west) -- (!>>>.south east);
          \draw [blue,Brace=10pt] (.south west) -- (!s.south east);
       }
       [5]
       {
          \draw [orange,Brace=15pt] (.south west) -- (!uu21.south east);
       }
    ]
    [3
       [6]
       {
          \draw [cyan,Brace=10pt] (.south west) -- (!s.south east);
       }
       [7]
    ]
  ]
\end{forest}
\end{document}
  • 'Relative node names' might be helpful if the OP looks in the manual, too. – cfr Oct 30 '17 at 4:53

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.