Forest: extending the upwards connection of forked edges

forest

I'm attempting to use forest with the forked edges option in order to draw family trees, which seems to work very well except for drawing children whose two parents are both shown in the tree. In this situation I would like to have a line connecting the parents from which the children are drawn. I have achieved something of the sort using an empty node:

\documentclass{standalone}

\usepackage[edges]{forest}

\begin{document}

\begin{forest}
  forked edges,
  [,phantom
    [Parent 1,draw,name=p1]
    [
      [Child 1,draw]
      [Child 2,draw]
    ]
    [Parent 2,draw,name=p2]
  ]
  \draw (p1)--(p2);
\end{forest}

\end{document}

This produces the following output:

forest

Obviously the gap between the actual tree connection below and the connection above is annoying, but I haven't found a way to remove it. Ideally I would be able to extend the upwards connection of the forked edge until it reaches the line between the parents. Is such a thing possible?

Best Answer

You can use the tikz key to add the missing lines. This has the advantage that you can define styles for that if you use this repeatedly.

\documentclass{standalone}

\usepackage[edges]{forest}

\begin{document}

\begin{forest}
  forked edges,
  [,phantom
    [Parent 1,draw,name=p1]
    [,tikz={\draw (.south)|-(p1);}
      [Child 1,draw]
      [Child 2,draw]
    ]
    [Parent 2,draw,name=p2,tikz={\draw ()--(p1);}]
  ]
\end{forest}
\end{document}

enter image description here

Related Question