11

I'm trying to build a family tree, and among the many examples I've found online this one has been the most useful:

How can I improve this family tree in TikZ?

However, there are two things I cannot do in that family tree as it is presented. I want to:

1) Add marriage ties further down in the tree and let the in-law spouse have their own family pedigree, and

2) I want to add multiple spouses for one person (I'm doing this for a pre-modern Chinese family, the pater familias simultaneously had a primary and a secondary wife)

Any help would be greatly appreciated!

UPDATE

This is an approximation of the tree I want to draw. I have indicated male and female using triangles and circles, but I might just as well use shades of gray (as in the tree in the question linked above), since the names of the family members might not fit inside triangles and circles. Or perhaps the names could go below them. Anyway, the shape of the boxes is not essential.

Proposed family tree

  • Sure, the question's been updated! – Mårten Apr 23 '13 at 2:49
7

Here's my attempt. The codes are a bit clumsy, though.

enter image description here

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{trees,calc}

\begin{document}

\centering

\begin{tikzpicture}[font=\footnotesize]
\tikzset{
  % edge styles
  level distance=15mm,
  married/.style={edge from parent/.style={draw,double distance=3pt}},
  mleft/.style={grow=left,edge from parent path={(\tikzparentnode.west)--(\tikzchildnode.east)}},
  mright/.style={grow=right,edge from parent path={(\tikzparentnode.east)--(\tikzchildnode.west)}},
  % node styles
  man/.style={rectangle,fill=blue!20},
  wife1/.style={rectangle,fill=red!40,rounded corners},
  wife2/.style={rectangle,fill=red!15,rounded corners},
}

% Generation 0
% \node(<gen_label>)[<options>]{<name>}
%   % add children and coordinate labels as in the other generations
% ;

% 1st Generation
\node[man]{Gen1 M1} 
  child[mleft,married,level distance=20mm]{coordinate(G1C1) child{node[wife1]{Gen1 F1}}}
  child[mright,married,level distance=20mm]{coordinate(G1C2) child{node[wife2]{Gen1 F2}}}
;

% 2nd Generation
\node at(G1C1){}
  [edge from parent fork down]
  child[sibling distance=30mm]{node[man]{Gen2 M1}
    child[married,mleft]{coordinate(G2C1) child{node[wife1]{Gen2 F1}}}
  }
  child[missing]
;
\node at(G1C2){}
  [edge from parent fork down,sibling distance=15mm]
  child{node[wife1]{Gen2 F1}
    child[married,mleft]{child[level distance=10mm]{node[man]{Gen2 M2}}}
  }
  child{node[man]{Gen2 M3}
    child[married,mright]{coordinate(G2C3) child{node(G2F3)[wife1]{Gen2 F3}}}
  }
;

% 1st Generation Loner
\node[man]at($(G2F3)+(0,\tikzleveldistance)$){Gen1 M2} edge (G2F3);

% 3rd Generation
\node at(G2C1){}
  child{node[man]{Gen3 M1}}
;
\node at(G2C3){}
  [edge from parent fork down]
  child{node[man]{Gen3 M2}}
  child{node[man]{Gen3 M3}}
  child{node[man]{Gen3 M4}}
;

\end{tikzpicture}

\end{document}

Edit

In the codes I used coordinate(<label>) and node(<label>) to mark specific coordinates where the (sub-)tree of the next generation begins. The <label>s are names of those points that can be referred to later in drawing the tree. For example, the label (G1C1) is a shorthand for "generation 1 couple 1".

Notice that each generation, except the first, starts with \node at(<label>)...;. So essentially what I was doing was to attach a new generation to a specific coordinate marked in the previous generation. For example, Gen2 M1 is the offspring of couple 1 of the first generation G1C1. Thus, to add a previous generation, say Gen0, simply draw it as any other generation, label the point at which Gen1 begins (say (G0C1)), and modify the beginning of the 1st generation by adding at(G0C1):

\node[man] at(G0C1) {Gen1 M1}...;
  • Thank you so much that works great! I suspect I will make more family trees in the future. So for future reference, could you tell me how I would add a -1 generation beyond the first for example? Connecting it to either of the spouses? I've tried to infer it from the way the code is structured, but I'm simply too much of an amateur to figure it out by myself. – Mårten Apr 24 '13 at 2:22
  • 1
    @Mårten: You're welcome :) It would probably be useful to take a look at the TikZ documentation, Ch.18, which discusses how to draw trees using TikZ. I will make an edit to my answer to clarify part of the codes. – Herr K. Apr 24 '13 at 2:53
  • 1
    @Mårten: An explanation has been added to the answer. – Herr K. Apr 24 '13 at 3:32
5

Here is another possibility using the new genealogytree package.

To visualize the secondary wife relation, I added two styles secondary wife and secondary family to change the node color and draw the edges dashed. These can be used separately.

The diagram is build with two \genealogytree structures. The first one is for the main graph. The second one adds the parent Gen1 M2 which cannot be done directly.

enter image description here

\documentclass{article}
\usepackage[all]{genealogytree}

\begin{document}

\begin{tikzpicture}
\gtrset{
  timeflow=down,               % time flows down
  processing=tcbox*,           % draw nodes with tcolorbox
  node size from=8mm to 5cm,   % width of nodes
  level size=6mm,              % height of nodes
  level distance=10mm,         % generation distance
                               % redefine default setting for female,male,neuter:
  tcbset={
    female/.style={colback=red!40,colframe=red!40!black,arc=2mm},
    male/.style={colback=blue!20,colframe=blue!40!black,sharp corners},
  },
  secondary wife/.style={box={colback=red!15,colframe=red!50,arc=2mm}},
  secondary family/.style={family edges={foreground={black,line width=0.25mm,dashed}}},
  %
  box={size=fbox,drop fuzzy shadow},    % node settings
  %
  edges={foreground={black,line width=0.25mm},    % edge settings
         background={white,line width=0.5mm}}
}

\genealogytree
{
  child{
    p[female]{Gen1 F1}
    g[male]{Gen1 M1}
    child{
      p[female]{Gen2 F1}
      g[male]{Gen2 M1}
      c[male]{Gen3 M1}
    }
    union[secondary family]{
      p[secondary wife]{Gen1 F2}
      child{
        p[male]{Gen2 M2}
        g[female]{Gen2 F2}
        c[phantom]- % reserve space (for safety)
      }
      child{
        g[male]{Gen2 M3}
        p[female,id=Gen2-F3@1]{Gen2 F3}% remember node
        c[male]{Gen3 M2}
        c[male]{Gen3 M3}
        c[male]{Gen3 M4}
      }
    }
  }
}

\genealogytree[set position=Gen2-F3@2 at Gen2-F3@1]% place at remembered position
{
  child{
    g[male]{Gen1 M2}
    c[phantom*,id=Gen2-F3@2]-
  }
}
\end{tikzpicture}

\end{document}
2

forest is not really designed for this kind of graph but it can still do quite well with a little patience. The best way to specify the tree is not, however, semantically expressive: the relations specified in drawing the tree do not represent the relations illustrated by the diagram.

This uses an experimental package, justtrees. There is a copy around somewhere but ask me for version 0.03 if you want to try it. justtrees makes it very easier to specify the generational labels shown on the right in the OP's drawing, but which are omitted in the other answers presented.

I've used a pink colour for female (sigh), blue for male (sigh again), and purple for 'secondary wives' (scream). An equals sign is used to specify the marriage relation.

\PassOptionsToPackage{rgb,x11names,svgnames,dvipsnames}{xcolor}
\documentclass[tikz,border=5pt,multi]{standalone}
\usepackage{justtrees}% version 0.03
\usetikzlibrary{shadows}
\begin{document}
  \forestset{
      reln/.style={
        content={$=$},
        really no edge,
        inner xsep=0pt,
      },
      really no edge/.style={
        edge={draw=none}
      },
  }
  \begin{justtree}
    {% tree preamble goes here
      person/.style={draw=#1, inner color=#1!10, outer color=#1!15, text=#1, thick, rounded corners, drop shadow},
      fe/.style={person=WildStrawberry},
      fe2/.style={person=WildStrawberry!50!DeepSkyBlue4},
      ma/.style={person=DeepSkyBlue4},
      just format/.style={font=\itshape},
      for tree={
        edge path={
          \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-5pt) -| (.child anchor)\forestoption{edge label};
        },
        edge={thick},
      }
    }
    [female, fe, right just={first generation}]
    [, reln
      [female, fe, really no edge, right just={second generation}]
      [, reln
        [male, ma, calign with current, right just={third generation}]
      ]
      [male, ma]
      [male, ma, really no edge]
      [, reln, calign with current]
    ]
    [male, ma]
    [, reln
      [female, fe]
      [, phantom, calign with current]
      [male, ma]
    ]
    [female, fe2]
    [,phantom
      [, reln
        [male, ma]
        [male, ma]
        [male, ma]
      ]
    ]
    [male, ma
      [female, fe]
    ]
  \end{justtree}

\end{document}

family tree with generational descriptors aligned on right

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.