# Diagram using Forest package

I want to create the tree diagram shown below using Forest package. I know that this tree can be produced using Tikz package, but I want to practice and learn Forest package.

So, can anyone help?

• Welcome to TeX.SE. It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that shows what you have tried and how far you got so that we can help you with the specific issue you are having a problem with. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Oct 13 '14 at 18:07
• Isn't this question a bit like asking somebody else to play scales because you want to improve your piano playing? That is, if you want to practise with forest, why don't you try drawing the tree with it and see how far you get? I can't see how my drawing the tree will help you to practise at all ;). – cfr Oct 13 '14 at 21:18
• Also, this is texample.net/tikz/examples/work-breakdown-structure. Why didn't you post the code rather than the picture if you just wanted to know how to convert a tree to forest? Would have saved those helping from typing everything from scratch. – cfr Oct 16 '14 at 3:01

I am also learning forest. This is my attempt

\documentclass{article}
\usepackage{forest}

\tikzset{parent/.style={align=center,text width=2cm,fill=green!20,rounded corners=2pt},
child/.style={align=center,text width=2.8cm,fill=green!50,rounded corners=6pt},
grandchild/.style={fill=pink!50,text width=2.3cm}
}
\begin{document}
\begin{forest}
for tree={%
thick,
l sep=0.6cm,
s sep=0.8cm,
node options={draw,font=\sffamily},
edge={semithick,-Latex},
where level=0{parent}{},
where level=1{
minimum height=1cm,
child,
parent anchor=south west,
tier=p,
l sep=0.25cm,
for descendants={%
grandchild,
minimum height=0.6cm,
anchor=150,
edge path={
\noexpand\path[\forestoption{edge}]
(!to tier=p.parent anchor) |-(.child anchor)\forestoption{edge label};
},
}
}{},
}
[Drawing\\diagrams
[Defining node and arrow styles
[Setting shape
[Choosing color
]
]
]
[Positioning the nodes
[Using a Matrix
[Relatively
[Absolutely
[Using overlays]
]
]
]
]
[Drawing arrows between nodes
[Default arrows
[Arrow library
[Resizing tips
[Shortening
[Bending]
]
]
]
]
]
]
\end{forest}
\end{document}


• (+1) just for using grandchild ;). – cfr Oct 14 '14 at 23:04
• If somebody wants that the edge between child and grandchild touches the child, parent anchor=west, and ($(!to tier=p.parent anchor)+(0.5\pgflinewidth,0)$)|-(.child anchor)\forestoption{edge label}; can be used – Konne Jul 15 '16 at 17:50
• Nice solution, but the horizontal node alignment gets messed up, as soon as the node for the grandchild nodes exceeds one line. Is there a fix for that? – raedma Apr 18 '17 at 16:02

Because practise allegedly makes perfect. (But do note that I believe this only applies to the one who practises if, indeed, it applies at all.)

I've used cantarell to try to capture the sense of the font in the original diagram i.e. to give the tree a slightly more casual look than the default Computer Modern provides. The colours were mostly chosen using xcolor's list of x11names.

The only real tricks here are realising that the pink nodes need to occupy several levels (one per node for any sub-tree) and making the node and edge styles sensitive to the different levels. You could pass custom style definitions node-by-node but doing it by levels makes it easier to maintain and adapt the code.

I've used a slight shading to try to give the nodes a little more depth. However, this is easily removed if not to your liking.

\PassOptionsToPackage{x11names,rgb}{xcolor}
\documentclass[border=5pt,tikz]{standalone}

\usepackage{forest}
\usepackage[default]{cantarell}
\usepackage[T1]{fontenc}
\colorlet{linecol}{black!75}

\begin{document}
\pgfkeys{/forest,
my rounded corners/.append style={rounded corners=2pt},
}
\begin{forest}
for tree={
font=\sffamily,
line width=1pt,
draw=linecol,
fit=rectangle,
edge={thick, color=linecol, >={Triangle[]}, ->},
where level=0{%
l sep+=5pt,
calign=child,
calign child=2,
inner color=PaleGreen1!80,
outer color=PaleGreen1,
align=center,
my rounded corners,
for descendants={%
calign=first,
},
}{%
where level=1{%
inner color=Green2!80,
outer color=Green2,
my rounded corners,
align=center,
parent anchor=south west,
tier=three ways,
for descendants={%
child anchor=west,
parent anchor=west,
align=left,
anchor=west,
inner color=MistyRose1!80,
outer color=MistyRose1,
edge path={
\noexpand\path[\forestoption{edge}]
(!to tier=three ways.parent anchor) |-
(.child anchor)\forestoption{edge label};
},
},
}{}%
},
}
[Drawing\\Diagrams
[Defining node\\and arrow styles
[Setting shape
[Choosing colour
]
]
]
[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}


I'm not sure about the merits of drawing the tree like this. I am not that keen on the combination of rounded and straight corners, especially given the gaps this leads to when edges are drawn between the south west corner of nodes in level 1 and the nodes in level 2. I'm also not clear about the colours. There are 2 different shades of green and 1 shade of pink. Is this significant? Are the paler and deeper green related, but not as closely as the pink? I understand that the paler green is a main category and the deeper green are sub-categories. But the pink do not seem to all be distinct or well-defined sub-sub-categories. (Why is choosing arrow styles not with drawing arrows?) But maybe I'm just over-thinking an MWE...