1

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?

2 Answers 2

3

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

2
\documentclass[border=3mm]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{positioning}

\begin{document}
    \begin{forest}
for tree = {draw,
            forked edge,
        l sep = 8mm,
     fork sep = 5mm,
        s sep = 9mm,
            }
[,coordinate, name=root
      [Child 1]
      [Child 2]
]
\node[draw, left =of root, name=p1] {Parent 1};
\node[draw, right=of root, name=p2] {Parent 2};
\draw (p1)--(p2);
    \end{forest}
\end{document}

enter image description here

2
  • Thank you for your answer, but I don't know if this is what I'm looking for. I should've been a bit more clear: the real tree is much larger than the toy example here and the parents are themselves children of grandparents. It seems you've removed the parents from the tree structure, and unfortunately this won't work for my problem; in that case I might as well do the whole thing in tikz from scratch. Nov 8, 2021 at 1:06
  • @AstianthusViminalis, please edit your question and make it more clear. I just reproduce your image. Make it more close what you after.
    – Zarko
    Nov 8, 2021 at 1:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .