# Using the Forest package to root multiple nodes to a single node

I want to try and route multiple nodes for example 1, 2, 3 and 4 ALL to one single node called quartile. i don't want each node going to it's own node called 'quartile'. So basically I'm trying to ask how can I route 4 nodes to a single node as opposed to what I've got below which is 4 nodes to 4 nodes. Sorry I'm new to this forum but that's the best I can explain it. Also is there a better way to do this type of diagram? would it be better to do it horizontally instead? thank you for any help.

\usetikzlibrary{shadows}

\begin{forest} for tree={%
draw=black, minimum width=1cm, minimum height=1.3cm, rounded corners=3,
text height=1ex, text depth=0ex,
grow=east,reversed,
edge={black},
parent anchor=east,
child anchor=west,
if n children=0{tier=last}{}
}
[data
[L2T
[1[quartile]][2[quartile]][3[quartile]][4[quartile]]]
[CPS
[1[quartile]][2[quartile]][3[quartile]][4[quartile]]]
[HIA
[1[quartile]][2[quartile]][3[quartile]][4[quartile]]]
[ATT
[1[quartile]][2[quartile]]]
]
\end{forest}

• Welcome! Please always post complete code we can compile as it is much more useful than mere code fragments. – cfr Apr 17 '16 at 15:57
• You seem to have 14 nodes to 14 nodes. Do you want 14 nodes to 1 node? Or do you want 14 nodes to 4 nodes? – cfr Apr 17 '16 at 16:00
• sorry about that! I'd like 14 nodes to 4 nodes if possible, thank you – Jac Williams Apr 17 '16 at 16:06

Like this?

\documentclass[border=10pt,tikz,multi]{standalone}
\usepackage{forest}
\begin{document}

\begin{forest}
for tree={%
draw,
minimum width=1cm,
minimum height=1.3cm,
rounded corners=3,
},
before typesetting nodes={%
where n children=0{%
if={strequal(content(),"quartile")}{%
delay={%
replace by={[, phantom, tier=last, append]},
},
calign with current,
for siblings/.wrap pgfmath arg={%
tikz+={%
\draw (.parent anchor) -- (#1.child anchor);
}
}{name()},
}{%
delay={%
append={[, phantom, shape=coordinate, tier=last]}
}
}
}{}
},
before packing={%
for tree={%
grow'=0,
parent anchor=east,
child anchor=west,
}
}
[data
[L2T
[1]
[2]
[quartile]
[3]
[4]
]
[CPS
[1]
[2]
[quartile]
[3]
[4]
]
[HIA
[1]
[2]
[quartile]
[3]
[4]
]
[ATT
[1]
[quartile]
[2]
]
]
\end{forest}
\end{document}


# EDIT

You can also join the quartile nodes with a final node. However, note that this is now nothing like a tree and it would probably be more easily drawn with something else. Nonetheless, if you've done this much with forest, you might try something like this modification:

\begin{forest}
join/.style={%
tikz+={%
\draw [\foresteoption{edge}] (.parent anchor) -- (#1.child anchor);
}
},
for tree={%
draw,
minimum width=1cm,
minimum height=1.3cm,
rounded corners=3,
},
before typesetting nodes={%
where n children=0{%
if={strequal(content(),"quartile")}{%
append={[, phantom, tier=very last]},
delay={%
replace by={[, phantom, tier=last, append]},
},
calign with current,
join=bl,
for siblings/.wrap pgfmath arg={%
append={[, phantom, shape=coordinate, tier=last]},
join=#1,
}{name()},
}{%
}
}{}
},
before packing={%
for tree={%
grow'=0,
parent anchor=east,
child anchor=west,
}
}
[data
[L2T
[1]
[2]
[quartile, name=q1]
[3]
[4]
]
[CPS
[1]
[2]
[quartile, name=q2]
[3]
[4]
]
[, phantom, tier=very last, calign with current
[beyond last, calign with current, name=bl]
]
[HIA
[1]
[2]
[quartile, name=q3]
[3]
[4]
]
[ATT
[1]
[quartile, name=q4]
[2]
]
]
\end{forest}


# UPDATE

I would probably try something like this, however, as I think it makes the diagram a bit clearer:

\documentclass[border=10pt,tikz,multi]{standalone}
\usepackage{forest}
\useforestlibrary{edges}
\begin{document}
\forestapplylibrarydefaults{edges}
\begin{forest}
join/.style={%
\draw  (.parent anchor)  -- ++(\forestoption{fork sep},0) |- (#1.child anchor);
}
},
forked edges,
for tree={%
draw,
minimum width=1cm,
minimum height=1.3cm,
rounded corners=3,
anchor=west,
},
before typesetting nodes={%
where n children=0{%
if={strequal(content(),"quartile")}{%
append={[, phantom, tier=very last]},
delay={%
replace by={[, phantom, shape=coordinate, calign with current, append]},
},
calign with current,
tier=last,
no edge,
anchor=west,
join=bl,
for siblings/.wrap pgfmath arg={%
append={[, phantom, shape=coordinate, tier=last]},
join=#1,
}{name()},
}{%
}
}{}
},
before packing={%
for tree={%
grow'=0,
parent anchor=east,
child anchor=west,
}
}
[data
[L2T
[1]
[2]
[quartile, name=q1]
[3]
[4]
]
[CPS
[1]
[2]
[quartile, name=q2]
[3]
[4]
]
[, phantom, calign with current, shape=coordinate
[beyond last, tier=very last, calign with current, name=bl]
]
[HIA
[1]
[2]
[quartile, name=q3]
[3]
[4]
]
[ATT
[1]
[quartile, name=q4]
[2]
]
]
\end{forest}
\end{document}

• That's perfect thank you! Is there anyway all four quartile nodes could now go to one end node? – Jac Williams Apr 17 '16 at 16:39
• As in all quartile nodes end up at a final node (i.e the opposite of the beginning of the diagram) – Jac Williams Apr 17 '16 at 18:40
• Please see edit and update above. – cfr Apr 17 '16 at 20:17