# Forest: parent node positioned incorrectly in relation to children [duplicate]

The tree below is produced by the code beneath it. In the tree, the parent node is slightly out of alignment. You will notice that the edges to its children are asymmetrical: the one on the left is slightly shorter than the one on the right.

I cannot figure out what is causing this—perhaps it is something to do with the use of nodeparts. How can I ensure that the parent node in this tree will be properly positioned to ensure symmetrical edges?

EDIT: Schrödinger's cat provided an answer which reminds me that I would like the solution to preserve the spaces between different levels of the tree in more complex trees, and to keep the separation between a parent and its child constant even if more branches are added.

For example, in the slightly more complex tree below the spacing between parent and children and between siblings is good, but the same asymmetry can be noticed between the root node and its children, and additionally the lowest node on the tree is connected to its parent by a slanted line when I would like it to be a straight vertical line.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart, positioning}

\usepackage{xinttools}

\usepackage{forest}

\def\numname#1{%
\ifcase#1 \or one\or two\or three\or four\or five\or six\or seven\or eight\or nine\or ten\or eleven \or twelve\or thirteen\or fourteen\or fifteen\or sixteen\or seventeen\or eighteen\or nineteen\or twenty\fi%
}

\newcounter{cellnum}
\newcommand{\tape}[1]{%
\setcounter{cellnum}{1}
\xintFor* ##1 in {#1} \do {%
\nodepart[text width=1.5ex, align=center]{\numname{\value{cellnum}}} $##1$%
\stepcounter{cellnum}%
}
}

\begin{document}

\begin{forest}
for tree={
delay={
content={\tape{#1}}
},
rectangle split,
rectangle split horizontal,
rectangle split parts=\value{cellnum},
rectangle split part align=base,
draw,
l sep=6ex,
s sep=2em,
edge path={
\noexpand\path[draw]
([yshift=-2.5ex]!u.children) -- ([yshift=1ex].parent);
},
tikz={\node[below=0cm of .\numname{#1} south, font=\scriptsize]{$#2$};}
}
}
]
\end{forest}

\end{document}

• Adding anchor=parent to for tree solves this problem, making this probably a duplicate of tex.stackexchange.com/questions/508172/…. I should have searched more thoroughly before asking. Feb 21, 2020 at 6:59
• @dexteritas Yes—that's the question I linked to in my comment above yours. Feb 21, 2020 at 9:25

You can use calign=fixed edge angles.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart, positioning}

\usepackage{xinttools}

\usepackage{forest}

\def\numname#1{%
\ifcase#1 \or one\or two\or three\or four\or five\or six\or seven\or eight\or nine\or ten\or eleven \or twelve\or thirteen\or fourteen\or fifteen\or sixteen\or seventeen\or eighteen\or nineteen\or twenty\fi%
}

\newcounter{cellnum}
\newcommand{\tape}[1]{%
\setcounter{cellnum}{1}
\xintFor* ##1 in {#1} \do {%
\nodepart[text width=1.5ex, align=center]{\numname{\value{cellnum}}} $##1$%
\stepcounter{cellnum}%
}
}

\begin{document}

\begin{forest}
for tree={
delay={
content={\tape{#1}}
},
calign=fixed edge angles,
rectangle split,
rectangle split horizontal,
rectangle split parts=\value{cellnum},
rectangle split part align=base,
draw,
l sep=6ex,
s sep=2em,
edge path={
\noexpand\path[draw]
([yshift=-2.5ex]!u.children) -- ([yshift=1ex].parent);
},
tikz={\node[below=0cm of .\numname{#1} south, font=\scriptsize]{$#2$};}
}
}

• @solisoc Well, what can I say. When I was writing an answer to your previous question, I was actually oscillating between shapes.multipart and using a tabular. It is great that you found the option that I thought to be an alternative. What is less great (please forgive me that I say this) is that you only specify part of the requirements. So all I can do is to write an answer based on what I see. I did this here and in you previous question. I am sorry, I cannot read minds (even though I am a cat ;-).