6

I am trying to alter the code I made for a family tree using TikZ, by inserting birthdays in a row below a name. Here is the initial code, without the birthday rows, which has a nice output (if someone knows how to post output here, please do so and delete this parenthetical request):

  \documentclass{article}
  \usepackage{tikz}
  \usepackage[active,tightpage]{preview}
  \PreviewEnvironment{tikzpicture}
  \setlength\PreviewBorder{5pt}

  \usetikzlibrary{trees}
  \usetikzlibrary{shapes}


  \begin{document}


  \begin{tikzpicture}
   [-,thick,
    every node/.style={shape=rectangle,inner sep=3pt,draw,thick}]
    \footnotesize
\node {Parent} [edge from parent fork down]
[sibling distance=2cm]
child {node {Child}
[sibling distance=2.2cm]
  child {node {Grandchild 1}}
  child {node {Grandchild 2}}
  child {node {Grandchild 3}}
  }
  ;
\end{tikzpicture}

  \end{document}

I tried to add some second rows with birthdays using the following code between the \begin{document} and \end{document}, but the output looks bad. Connecting lines change or disappear or show up in the wrong place. (If you can post output for the code below, please do so and delete this parenthetical request.)

  \begin{tikzpicture}
   [-,thick,
    every node/.style={shape=rectangle,inner sep=3pt,draw,thick}]
    \footnotesize
\node {Parent} [edge from parent fork down]
[sibling distance=2cm]
    child{node [name=block2, rectangle split, rectangle split parts=2]
      {Child \nodepart{second}1/15/59}
[sibling distance=2.2cm]
 child{node [name=block2, rectangle split, rectangle split parts=2]
      {Grandchild 1\nodepart{second}10/20/80}}
  child{node [name=block2, rectangle split, rectangle split parts=2]
       {Grandchild 2\nodepart{second}2/5/84}}
  child{node [name=block2, rectangle split, rectangle split parts=2]
      {Grandchild 3\nodepart{second}8/9/89}}
}
 ;
 \end{tikzpicture}

Can someone advise how to include the second birthday rows without altering the tree structure from the original code?

KCd
  • 295

1 Answers1

7

Using the align= key you can introduce line breaks for the dates:

 \documentclass{article}
  \usepackage{tikz}
  \usepackage[active,tightpage]{preview}
  \PreviewEnvironment{tikzpicture}
  \setlength\PreviewBorder{5pt}

  \usetikzlibrary{trees}
  \usetikzlibrary{shapes}


  \begin{document}


  \begin{tikzpicture}
   [-,thick,
    every node/.style={shape=rectangle,inner sep=3pt,draw,thick,align=center}]
    \footnotesize
\node {Parent\\ 1/15/59} [edge from parent fork down]
[sibling distance=2cm]
child {node {Child\\1/15/59}
[sibling distance=2.2cm]
  child {node {Grandchild 1\\1/15/59}}
  child {node {Grandchild 2\\1/15/59}}
  child {node {Grandchild 3\\1/15/59}}
  }
  ;
\end{tikzpicture}

  \end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • This works very nicely (and simply). I had tried using \ before to create a new line, but I wasn't using an align= command so the \ wasn't working. Thanks! – KCd Sep 29 '12 at 01:20