2

I have to draw many simple trees similar to the ones depicted for instance at page 128 or 133 of this beautiful book by Cheng and Lauda. I used to have some knowledge of the package forest, but unfortunately I now realise that I have forgotten most of it (although I guess I should play with the circle or encircle option, somehow).

The best would be a simple macro using forest or qtree allowing to draw these upward growing, unlabelled trees.

5

You could start here:

\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
  for tree={%
    label/.option=content,
    grow=north,
    content=,
    circle,
    fill,
    minimum size=3pt,
    inner sep=0pt,
  }
  [
    [ [][] ]
    [ [][][][] ]
  ]
\end{forest}
\end{document}

enter image description here

  • 1
    Wonderful, many thanks! Quick remark for anybody interested in the same question: with the option grow=north the tree is drawn from right to left; in case you prefer the left to right version, then right option is grow'=north. – Andrea Gagna Feb 16 at 16:58
4

I've no experience with forest (DG's answer seems a good place to start) but have recreated one of the figures in the book using the tikz trees library (only), in case you decided that the forest package wasn't necessary and/or were already familiar with drawing in tikz.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees} 
\begin{tikzpicture}[
level 1/.style={grow via three points={one child at (0,1) and two children at (-.5,1) and (.5,1)}},
level 2/.style={grow via three points={one child at (0,1) and two children at (-.25,1) and (.25,1)}},
level 3/.style={grow via three points={one child at (0,1) and two children at (-.125,1) and (.125,1)}},
every node/.style={circle, fill=black, inner sep = .25ex, minimum size=.25ex}]
\node {} 
child{
    node {} 
    child{
        node {}
        child{node {}}
        child[very thick]{node {}}
        child{node {}}
        }
    child{
        node {}
        }
    }
child{
    node {} 
    child{
        node {}
        child foreach \x in {1,2,3} {node {}}
        }
    child{
        node {}
        }
    }
child{
    node {} 
    child{
        node {}
        child[red]{node {}}
        child[missing]
        }
    child{
        node {}
        }
    }
child{
    node {} 
    child{
        node {}
        }
    child{
        node {}
        child{node {}}
        child[missing]
        child{node {}}
        }
    child{
        node {}
        }
    };
\end{tikzpicture}

tree_example

The drawing trees with tikz is explained in section 21 Making Trees Grow of the tikz manual. Noteworthy in this example:

  • The coordinates in each style at the start of the picture determine the placement of children at the level indicated
  • Individual children (edges) and nodes (vertices) can have their own styling (for example, very thick)
  • The missing key is useful to create a child that 'takes up space' but is not visible (such as that adjacent to the edge highlighted in red above)
  • If all children are going to be the same, you can use a foreach construct

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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