Centre align child nodes from parent node whilst shifting anchor

Following on from forest respecify branch positions 2, if there are an odd number of nodes I would like the middle one to be centred.

The manual (p71) says to use this:

\begin{forest}
[manual correction of B
[A[1][2][3][4]]
[B,before computing xy={s/.average={s}{siblings}}]
[C[1][2][3][4]]
]
\end{forest}


This gets B centred nicely.

However, if I change the anchor point so that the edges emanate from the east point of a node, it still uses the centrepoint of the node for calculation purposes. How would I adjust this so that the anchor point is the new centre of the node.

 \documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{forest}
\begin{document}
\begin{forest}
[top, s sep=1cm,child anchor=90
[A,child anchor=90]
[B,parent anchor =south,before computing xy={s/.average={s}{siblings}}]
[{CDDDDDDDD}, parent anchor=-10
[A]
[B]
[C,before computing xy={s/.average={s}{siblings}}]
[D]
[E]
]
]
\end{forest}
\end{document}


i.e. the C in the bottom row is vertically below the start of the edges leading to A B C D E, rather than vertically below the middle of the parent node? Probably needs some horizontal shift by the length of the parent node's contents.

• You're missing \begin{document}. And \begin{forest}. – cfr Jun 18 '18 at 23:25

Do you want something like this?

If so, I suggest using a style I use to align middle children (where there are such). If you do this, you can also greatly simplify your existing code by eliminating the need to get averages etc. and some (but not all) anchor specifications can be removed.

Note that there is rarely any point in specifying child anchor for the root node. Sometimes there is, but such cases are rare. You may have wanted parent anchor here instead.

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{forest}
\forestset{
align middle child/.style={
before typesetting nodes={
if={
> Ow+P {n children}{isodd(##1)}
}{
calign child/.process={
Ow+n {n children}{(##1+1)/2}
},
calign=child edge,
}{},
},
},
align middle children/.style={
for tree={align middle child},
},
}
\begin{document}
\begin{forest}
align middle children
[top, s sep=1cm
[A, child anchor=90]
[B]
[{CDDDDDDDD}, parent anchor=-10
[A]
[B]
[C]
[D]
[E]
]
]
\end{forest}
\end{document}

• I agree with your comment. +1. – marmot Jun 18 '18 at 23:42
• @marmot Sorry. I felt mean and I didn't want to be. – cfr Jun 18 '18 at 23:44
• You are not mean. Your solution is much better than my proposal. – marmot Jun 18 '18 at 23:44
• No, just honest and realistic. (And most of my little bit of knowledge on forest came from your posts anyway, but I get more and more fascinated by that package. It does so many great things without running into the expansion issues one has with pgfplots, which is of course also great.) – marmot Jun 18 '18 at 23:54
• thanks marmot & @cfr, in the meantime I made some progress just putting in "calign with current edge" in the central nodes, seemed to work quite nicely... – A. D Jun 19 '18 at 11:57