5

I am a beginner in latex and am very interested in exploring it's wide range of features. I wanted to build a family tree and decided to use the forest package. I use this manual - forest_doc.

I started building a tree that would have forked edges. I learnt from section 4.2 that forked edges command modifies the parent anchor and child anchor and sets the necassary edge path. But I want a child that has different parent anchor and that undergoes manual correction. I figured the manual correction part. But the anchoring, I'm not able to overwrite.

Here is my code:

\documentclass[border=10pt]{standalone}

\usepackage[edges]{forest} \usepackage{xcolor}

\begin{document} \begin{forest} man/.style = {fill=blue!70}, woman/.style = {fill=green}, for tree={draw={black, thick}, edge = {draw, thick}, rounded corners, inner sep=5pt}, [Parent, man [Wife, woman, for tree={grow=0} , before drawing tree={x+=5.5cm, y+=1cm}] [Child, man, forked edges [Grand Child, man] [Grand Child, woman] ] [Child, woman, forked edges [Grand Child, man] [Grand Child, man] ] ] \end{forest} \end{document}

And the result:

Result

I want the Wife node's edge to start from Parent's east not from south. Please let me know what option should I give. I tried parent anchor and child anchor and none worked. Thanks in advance!

2 Answers2

4

Small variation of the @hpekristiansen first answer:

\documentclass[border=3.141592]{standalone}
\usepackage[edges]{forest}

\begin{document} \begin{forest} for tree={ % common nodes style draw, thick, rounded corners, % styles man/.style = {fill=cyan!30}, woman/.style = {fill=teal!30}, % tree forked edge, edge = {-, semithick}, } [Parent, man, name=P [Wife, woman, name=W, no edge, for tree={grow=east, anchor=base}, before computing xy={l=-0mm,s=33mm}, ] [Child, man, [Grand Child, man] [Grand Child, woman] ] [Child, woman, [Grand Child, man] [Grand Child, man] ] ] \draw[semithick] (P) -- (W); \end{forest} \end{document}

enter image description here

Zarko
  • 296,517
  • This one is nice as well, thanks! I have read this manual correction in the first alternative here. The difference is forked edges and custom tikz does the trick! – Veera Raagavan Jun 22 '21 at 17:41
2

I do not know much about forest, so I do not know if it is possible. It seems that forked edges move the edge anchor to one point. A possibility is to have no edge and then draw it afterwards, like this:

\documentclass[border=10pt]{standalone}    
\usepackage[edges]{forest}
\begin{document}
    \begin{forest}
        man/.style = {fill=blue!70},
        woman/.style = {fill=green},
        for tree={draw={black, thick}, edge = {draw, thick}, rounded corners, inner sep=5pt},
        [Parent, man,
            [Wife, woman, for tree={grow=0} , before drawing tree={x+=5.5cm, y+=1cm}, no edge] {\draw[thick] () -- (!u);}
            [Child, man, forked edges
                [Grand Child, man]
                [Grand Child, woman]
            ]
            [Child, woman, forked edges
                [Grand Child, man]
                [Grand Child, man]
            ]
        ]
    \end{forest}
\end{document}

Forest with horizontal line between parent and wife

Edit:

By making a phantom root, you can make both Parent and Wife children at the same level and thereby automatically align them like this:

\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\begin{document}
    \begin{forest}
        man/.style = {fill=blue!70},
        woman/.style = {fill=green},
        for tree={draw={black, thick}, edge = {draw, thick}, rounded corners, inner sep=5pt},
        [,phantom[Parent, man
            [Child, man, forked edges
                [Grand Child, man]
                [Grand Child, woman]
            ]
            [Child, woman, forked edges
                [Grand Child, man]
                [Grand Child, man]
            ]
        ] [Wife, woman, no edge] {\draw[thick] () -- (!p);}]
    \end{forest}
\end{document}
  • Thanks a lot for the idea! I used the first alternative. I changed the coordinates a bit so that I got it truly flat. As I'm planning to introduce wedded ones to each node, I felt [,phantom] would make the code really complicated. I'm still learning how tikz can be injected while using forest (even tikz itself in fact).

    I am welcome to learn how forest itself provides for such usages as this

    – Veera Raagavan Jun 22 '21 at 17:14