[Tex/LaTex] Growing Trees with Forest package

foresttrees

Is it possible to use the forest package grow a tree so that the children are stacked vertically, like this:
a tree node with many children

I ended up doing this: If the parent is A and has three children B C D, and I want to attach all the kids as shown above, I had to do this:

\begin{forest}
for tree={
draw,
%  minimum height=2cm,
%  anchor=west,
align=center
% calign
%  child anchor=west
},
[{ROOT},  align=center
[{ A} , parent anchor=south, child anchor=north  
[{B}, parent anchor=east,  anchor=east, child anchor=east , calign=child edge 
[{C}, parent anchor=east, anchor=east, child anchor=east, calign=child edge
    [{D}, parent anchor=east, anchor=east, child anchor=east 
    ]
  ]
 ]
]
\end{forest}

As you can see, even though they are all children of A, I had to make B the parent of C and C the parent of D.

Best Answer

Not only have several people provided code for this diagram before, I've definitely answered it using Forest before.

It would be much easier if the image in the question was linked to the source since that might well give me a clue.

I know I've given a Forest solution because I found one, but I seem to have not given a link to my answer. And I remember being annoyed because I drew the diagram from scratch when the OP could have linked to code I could have copy-pasted and adapted, since it had been answered before (but maybe the code no longer worked or didn't use Forest or something).

This diagram is intensely annoying as this KEEPS happening to me.

Anyway, I updated the code I've got for Forest v.2 using a modified version of the code in my answer linked in Torbjørn T.'s comment. This version uses the folder style from the edges library.

\documentclass[border=5pt,tikz,multi]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows.blur}
\forestset{%
  colour me out/.style={outer color=#1!75, inner color=#1!50, draw=darkgray, thick, blur shadow, rounded corners},
  rect/.append style={rectangle, rounded corners=2pt},
  dir tree switch/.style args={at #1}{%
    for tree={
      edge=-Latex,
      font=\sffamily,
      fit=rectangle,
    },
    where level=#1{
      for tree={
        folder,
        grow'=0,
      },
      delay={child anchor=north},
    }{},
    before typesetting nodes={
      for tree={
        content/.wrap value={\strut ##1},
      },
      if={isodd(n_children("!r"))}{
        for nodewalk/.wrap pgfmath arg={{fake=r,n=##1}{calign with current edge}}{int((n_children("!r")+1)/2)},
      }{},
    },
  },
}

\begin{document}
\begin{forest}
  dir tree switch=at 1,
  for tree={
    font=\sffamily\bfseries,
    rect,
    align=center,
    edge+={thick, draw=darkgray},
    where level=0{%
      colour me out=green!50!white,
    }{%
      if level=1{%
        colour me out=green!95!black,
      }{%
        colour me out=magenta!50!orange!75!white,
        edge+={-Triangle},
      },
    },
  }
  [Drawing\\Diagrams
    [Defining node\\and arrow styles
      [Setting shape]
      [Choosing colour]
      [Adding shading]
    ]
    [Positioning\\the nodes
      [Using a matrix
        [Absolutely]
        [Relatively]
        [Using overlays]
      ]
    ]
    [Drawing arrows\\between nodes
      [Default arrows
        [Arrow library]
        [Re-sizing tips]
        [Shortening]
        [Bending]
      ]
    ]
  ]
\end{forest}
\end{document}

Forest 2 output

Related Question