# Package forest: Horizontal alignment of parent and child

Here's my forest:

How do I align Family1 and its A very long long long ... text child horizontally?

If I may ask another question here, how do I align the children's text to the left? I want only the text inside nodes Domain, Subdomain and Family center aligned, while the text inside children are left aligned. Currently they're all text centered.

Code:

\forestset{
no border/.style={
for tree={
edge path={
\noexpand\path [draw, thin, \forestoption{edge}] (!u.parent anchor) +(5pt,0) (.child anchor)\forestoption{edge label};
},
},
},
border/.style={
for tree={
edge path={
\noexpand\path [draw, thin, \forestoption{edge}] (!u.parent anchor) -- +(10pt,0) |- (.child anchor)\forestoption{edge label};
},
draw,
thin,
}
},
domain/.style={
text width=3cm,
parent anchor=south,
rotate=90,
fill=black, text=white
},
subdomain/.style={
text width=3cm,
parent anchor=south,
rotate=90
},
family/.style={
text width=3cm,
parent anchor=east,
tier=family,
calign=child,
calign primary child=1
},
}

\begin{figure}[!ht]
\begin{forest}
for tree={
parent anchor=east,
grow'=east,
text centered,
minimum width=2cm,
text width=9.8cm
}
[Domain, border, domain
[Subdomain, subdomain
[Family1, family
[A very long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text]
]
[Family2, family
[A very long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text]
]
[Family3, family
[A very long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text]
]
]
]
\end{forest}
\end{figure}

• If you have a recent version of Forest, consider using edge path' in place of edge path. (You can pass thin as edge+=thin, for example. – cfr Jan 9 '17 at 4:24

If I understand your first question correctly, you want to center align horizontally.

The nodes in question (FamilyX and its child), are already horizontally aligned (due to calign setting). More precisely, their anchors are. By default, Forest sets the node anchors to base. For multiline nodes, the base is at the first line of text. As a consequence, the first lines of the parent (FamilyX) and child (a very long long...) are aligned.

To (horizontally) align the centers of the nodes, say anchor=east (or center, or west) for both of them.

For the second question, use tikz key align, e.g. /tikz/align=flush left. You need to specify the path (/tikz/) because you don't want to invoke Forest's align key.

The entire code:

\documentclass{article}

\usepackage{forest}

\begin{document}

\forestset{
no border/.style={
for tree={
edge path={
\noexpand\path [draw, thin, \forestoption{edge}] (!u.parent anchor) +(5pt,0) (.child anchor)\forestoption{edge label};
},
},
},
border/.style={
for tree={
edge path={
\noexpand\path [draw, thin, \forestoption{edge}] (!u.parent anchor) -- +(10pt,0) |- (.child anchor)\forestoption{edge label};
},
draw,
thin,
}
},
domain/.style={
text width=3cm,
parent anchor=south,
rotate=90,
fill=black, text=white
},
subdomain/.style={
text width=3cm,
parent anchor=south,
rotate=90
},
family/.style={
text width=3cm,
parent anchor=east,
tier=family,
calign=child,
calign primary child=1,
anchor=east,
for children={
/tikz/align=flush left,
anchor=east,
}
},
}

\begin{figure}[!ht]
\begin{forest}
for tree={
parent anchor=east,
grow'=east,
text centered,
minimum width=2cm,
text width=9.8cm,
}
[Domain, border, domain
[Subdomain, subdomain
[Family1, family
[A very long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text]
]
[Family2, family
[A very long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text]
]
[Family3, family
[A very long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text]
]
]
]
\end{forest}
\end{figure}

\end{document}

• What would be so bad about align=left? – cfr Jan 9 '17 at 4:23
• Forest's align always introduces a tabular environment and so always requires manual line breaks (using \), whereas TIkz's align behaves differently according to whether text width is set or not. If it is set, we get alignment with line breaking: the node text will break into lines without explicit \s. See section 17.4.3 of PGF (v3) manual for further details. – Sašo Živanović Jan 9 '17 at 10:44
• You need to ping if more than one person has commented, by the way. I thought that was what you'd say. I guess I would think of using e.g. align={@{}p{<dim>}@{}} or similar. – cfr Jan 9 '17 at 22:49
• @cfr Argh, I always forget to ping. Yes, what you suggest would work just as well! – Sašo Živanović Jan 11 '17 at 1:57