Better draw connecting lines in a manually constructed family tree

tikz-pgf

After a few days of unsuccessful struggle with genealogytree, I've decided to manually draw a family tree with tikz. I've two questions about the MWE below:

Can the double line connecting node nBob to nAlice be aligned with the top line of nBob ("Bob") instead of its vertical midpoint?

And is there a more efficient way of drawing the lines connecting the children than manually specifying all those coordinates? I don't mind specifying the coordinates for the nodes (in fact, that's easier than trying to get genealogytree to place nodes reasonably). But it sure would be nice to say, draw the horizontal line and then connect it to the children nodes without having to specify the coordinates of the vertical connectors.

\documentclass[varwidth,margin=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  % How to align double line with "Bob" instead of vertical midpoint of (nBob)?
  \node[text width=2cm] (nBob) at (2,0) {\centering Bob\\the giant\par};
  \node (nAlice) at (6,0) {Alice};
  \draw[double] (nBob) -- (nAlice);

  \node (nBobby) at (1.5,-2) {Bobby};
  \node (nAlly)  at (4.5,-2) {Ally};
  \node (nOops)  at (7.5,-2) {Oops};

  % How to draw these lines more efficiently?
  \draw (4.25,0) -- (4.25,-1);
  \draw (1.5,-1) -- (7.5,-1);
  \draw (1.5,-1) -- (nBobby);
  \draw (4.5,-1) -- (nAlly);
  \draw (7.5,-1) -- (nOops);
\end{tikzpicture}
\end{document}

enter image description here

Edit: Here is Ignasi's answer where I've introduced a new problem: Sally. Sally is a child of Bob, but with a not-shown mother. There are two issues (I figured out a horizontal alignment issue that I posted a moment ago.)

  • The line from nBob to nSally passes through the label "the giant"
  • I don't understand why \draw (aux) -- (aux|-aux2) (aux2); works

Enhanced MWE:

\documentclass[varwidth,margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
  \node[minimum width=1.5cm, label={[anchor=north, yshift=1mm]below:the giant}] (nBob) {Bob};
  \node[minimum width=1.5cm,right=4cm of nBob] (nAlice) {Alice};
  \draw[double] (nBob) -- coordinate[pos=.6] (aux) (nAlice);

  \node[below=of nBob] (nSally) {Sally};
  \node[right=of nSally] (nBobby) {Bobby};
  \node[right=of nBobby] (nAlly) {Ally};
  \node[right=of nAlly] (nOops) {Oops};

  \draw (nBob) -- coordinate[pos=0.75] (aux2) (nSally);
  \draw (aux) -- (aux|-aux2) (aux2); % don't understand this line
  \draw (nBobby) -- (nBobby|-aux2)-|(nAlly);
  \draw (nBobby) -- (nBobby|-aux2)-|(nOops);
\end{tikzpicture}
\end{document}

enter image description here

Best Answer

There are, probably, better solutions, but this trick can solve the problem. Instead of using a multiline node, the second line is added as a label. This way Bob and Alice are aligned.

About positioning, I think it's better to use relative positioning with positioning library. And corners can be solved with |- or -| as @hpekristiansen suggested.

\documentclass[varwidth,margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
  % How to align double line with "Bob" instead of vertical midpoint of (nBob)?
  \node[minimum width=1.5cm, label={[anchor=north, yshift=1mm]below:the giant}] (nBob) {Bob};
  \node[minimum width=1.5cm,right=4cm of nBob] (nAlice) {Alice};
  \draw[double] (nBob) -- coordinate (aux) (nAlice);

  \node[below=of aux] (nAlly) {Ally};
  \node[left=of nAlly] (nBobby) {Bobby};
  \node[right=of nAlly] (nOops) {Oops};

  % How to draw these lines more efficiently?
  \draw (aux) -- coordinate[pos=0.75] (aux2) (nAlly);
  \draw (nBobby) -- (nBobby|-aux2)-|(nOops);
\end{tikzpicture}
\end{document}

enter image description here

Answer to updated question:

To avoid de problem with the vertical line crossing "the giant", we can add a name to the label (every label is a node) and draw the line between the label and Sally.

About the strange line \draw (aux) -- (aux|-aux2) (aux2);. It means draw a line between coordinate aux and the intersection of a vertical line through aux and an horizontal line through aux2, and then place the pen again over aux2. This last movement is not necessary. It should be \draw (aux)--(aux|-aux2);.

\documentclass[varwidth,margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
  \node[minimum width=1.5cm, label={[anchor=north, yshift=1mm, name=giant]below:the giant}] (nBob) {Bob};
  \node[minimum width=1.5cm,right=4cm of nBob] (nAlice) {Alice};
  \draw[double] (nBob) -- coordinate[pos=.6] (aux) (nAlice);

  \node[below=of nBob] (nSally) {Sally};
  \node[right=of nSally] (nBobby) {Bobby};
  \node[right=of nBobby] (nAlly) {Ally};
  \node[right=of nAlly] (nOops) {Oops};

  \draw (giant) -- coordinate[pos=0.5] (aux2) (nSally);
  \draw (aux) -- (aux|-aux2);% (aux2); % don't understand this line
  \draw (nBobby) -- (nBobby|-aux2)-|(nAlly);
  \draw (nBobby) -- (nBobby|-aux2)-|(nOops);
\end{tikzpicture}
\end{document}

enter image description here