# How to layout a vertical Icicle tree with the forest package

This page presents a way to create icicle trees. It works very well as soon as the content of each node is drawn on one line. For the following example, (that contains only few additional nodes), the result is erroneous. Any idea on the way to fix that automatically ? Thanks.

Latex code (a slightly modified version of the original code):

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\usetikzlibrary{backgrounds}
\tikzset{
basic/.style = {line width=1pt,draw=black},
L0/.style = {align=left,  fill=green!30},
L1/.style = {align=left, fill=green!20,},
L2/.style = {align=left, fill=pink!60, },
L3/.style = {align=left, fill=pink!10},
L4/.style = {align=left, fill=green!10},
L5/.style = {align=left, fill=blue!10},
t0/.style={text width=2cm,},
t1/.style={text width=6cm,},
t2/.style={text width=9em},
t3/.style={text width=5em},
t4/.style={text width=5em},
t5/.style={text width=5em},
}
% modified from Zarko's answer at http://tex.stackexchange.com/a/314181/ and my answer at http://tex.stackexchange.com/a/314249/
\begin{document}
\begin{forest}
for tree={
grow'=0,
parent anchor=children,
child anchor=parent,
edge path={none},
minimum width=15mm,
l sep=0pt,
s sep=0pt,
if n children=0{
minimum height=8mm,
}{},
node options/.wrap pgfmath arg={t#1}{level()},
},
before drawing tree={
where n children=0{
tikz+/.wrap pgfmath arg={
\scoped[on background layer]{\path [L#1, basic] (.north west) rectangle (.south east);}
}{level()},
}{
tikz+/.wrap pgfmath arg={
\scoped[on background layer]{\path [L#1, basic] (.west |- !L.south) rectangle (.east |- !F.north);}
}{level()},
}
}
[OP10
[Defining node and arrow styles
[Setting shape
[my define1]
[my definet]
]
[Choosing color on a very huge line
[my definet]
]
[Positioning the nodes
[Using a Matrix [Extra content]]
[Relatively [Extra content2 [extra content 3] [extra content 4]]]
[Absolutely]
[Using overlays] ]
[Drawing arrows between nodes
[Default arrows ]
[Arrow library]
[Resizing tips]
[Shortening]
[Bending] ] ]
\end{forest}
\end{document}


Result (look around the extra content texts):

Welcome to TeX.SE! It depends on what you want. If you want a minimal damage fix, consider

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\usetikzlibrary{backgrounds}
\tikzset{
basic/.style = {line width=1pt,draw=black},
L0/.style = {align=left,  fill=green!30},
L1/.style = {align=left, fill=green!20,},
L2/.style = {align=left, fill=pink!60, },
L3/.style = {align=left, fill=pink!10},
L4/.style = {align=left, fill=green!10},
L5/.style = {align=left, fill=blue!10},
t0/.style={text width=2cm,},
t1/.style={text width=6cm,},
t2/.style={text width=9em},
t3/.style={text width=5em},
t4/.style={text width=5em},
t5/.style={text width=5em},
}
% modified from Zarko's answer at http://tex.stackexchange.com/a/314181/ and my answer at http://tex.stackexchange.com/a/314249/
\begin{document}
\begin{forest}
for tree={
grow'=0,
parent anchor=children,
child anchor=parent,
edge path={none},
minimum width=15mm,
l sep=0pt,
s sep=0pt,
if n children=0{
minimum height=8mm,
}{},
node options/.wrap pgfmath arg={t#1}{level()},
},
before drawing tree={
where n children=0{
tikz+/.wrap pgfmath arg={
\scoped[on background layer]{\path [L#1, basic] (.north west) rectangle (.south east);}
}{level()},
}{
tikz+/.wrap pgfmath arg={
\scoped[on background layer]{\path [L#1, basic] (.west |- !L.south) rectangle (.east |- !F.north);}
}{level()},
}
}
[OP10
[Defining node and arrow styles
[Setting shape
[my define1]
[my definet]
]
[Choosing color on a very huge line
[my definet,minimum height=14mm]
]
[Positioning the nodes
[Using a Matrix [Extra content]]
[Relatively [Extra content2 [extra content 3] [extra content 4]]]
[Absolutely]
[Using overlays] ]
[Drawing arrows between nodes
[Default arrows ]
[Arrow library]
[Resizing tips]
[Shortening]
[Bending] ] ]
\end{forest}
\end{document}


If you want a real solution, hope that cfr shows up and sees this. ;-)

• The problem with Zarko's (?) code is that the height of a node is determined by what is right of it. However, in your example, the left node is already higher than what is right of it. One would need to use the maximum of the respective dimensions. This can be done with calc. What prevents me from doing that is that, at the very moment I am done, a super elegant answer by cfr will pop up. So now I am hoping this answer will pop up without me writing a complicated answer first. ;-) – marmot Oct 1 '18 at 23:14
• Thanks for your answer. I see that I should put the size also for the relatively cell. In my use case the latex code will be automatically generated, so I cannot rely on manual fixes. (previous message edited because it was wrong) – rgiot Oct 2 '18 at 6:10
• @rgiot I know that this is just an ad hoc fix for this very tree. This means that, yes, if you have a different table, the minimum height will be inappropriate. If cfr does not show up in a while, I will be happy to add a not-so-elegant solution. However, I cannot understand your second comment. Can you try to reword it? – marmot Oct 2 '18 at 6:17