Text FormattingAdjusting text in family tree nodes

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
anta40
Posts: 38
Joined: Thu Sep 11, 2008 2:36 pm

Adjusting text in family tree nodes

Post by anta40 »

Let's say we have this hypothetical family tree

Code: Select all

\documentclass{beamer}
\usepackage{tikz}
\usepackage{verbatim}
%\usepackage[active,tightpage]{preview}
%\PreviewEnvironment{tikzpicture}
%\setlength\PreviewBorder{15pt}%
\usetheme{default}
\usetikzlibrary{trees}
\begin{document}


\begin{frame}{Hello}

A fictionary family tree

\begin{center}
\begin{tikzpicture}[
  man/.style={rectangle,draw,fill=blue!20},
  woman/.style={rectangle,draw,fill=red!20,rounded corners=.8ex},
  grandchild/.style={grow=down,xshift=1em,anchor=west,
    edge from parent path={(\tikzparentnode.south) |- (\tikzchildnode.west)}},
  first/.style={level distance=6ex},
  second/.style={level distance=12ex},
  third/.style={level distance=18ex},
  level 1/.style={sibling distance=5em}]
    % Parents
    \coordinate
      child[grow=left] {node[man,anchor=east]{Cyrus the Great}}
      child[grow=right] {node[woman,anchor=west]{Elizabeth}}
      child[grow=down,level distance=0ex]
    [edge from parent fork down]
    % Children and grandchildren
    child{node[man] {John the Conqueror}}
    child{node[man] {Ivan the Terrible}}
    child {node[woman] {Joanne of Arc}}
    child {node[man] {Richard Lionheart}}
    child {node[woman]{Mata Hari}};
\end{tikzpicture}
\end{center}
\end{frame}



\end{document}
Due to long names, the nodes will be jammed like this. So I have several questions in mind:
1. How to insert linebreaks into the nodes?
2. How to adjust the fonst size?
3. How to adjust the distance between nodes?

Thank you
Attachments
ft.jpg
ft.jpg (40.91 KiB) Viewed 5549 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Adjusting text in family tree nodes

Post by Stefan Kottwitz »

You can do all this by modifying styles.
  1. You can use \\, but add an alignment option, such as align=center.
  2. Add an option such as font=\small.
  3. Adjust a distance value, such as level 1/.style={sibling distance=6em}].
A complete example with the changes:

Code: Select all

\documentclass{beamer}
\usepackage{tikz}
\usepackage{verbatim}
%\usepackage[active,tightpage]{preview}
%\PreviewEnvironment{tikzpicture}
%\setlength\PreviewBorder{15pt}%
\usetheme{default}
\usetikzlibrary{trees}
\begin{document}


\begin{frame}{Hello}

A fictionary family tree

\begin{center}
\begin{tikzpicture}[
  man/.style={rectangle,draw,fill=blue!20,align=center,font=\small},
  woman/.style={rectangle,draw,fill=red!20,rounded corners=.8ex,align=center,font=\small},
  grandchild/.style={grow=down,xshift=1em,anchor=west,
    edge from parent path={(\tikzparentnode.south) |- (\tikzchildnode.west)}},
  first/.style={level distance=6ex},
  second/.style={level distance=12ex},
  third/.style={level distance=18ex},
  level 1/.style={sibling distance=5em}]
    % Parents
    \coordinate
      child[grow=left] {node[man,anchor=east]{Cyrus the Great}}
      child[grow=right] {node[woman,anchor=west]{Elizabeth}}
      child[grow=down,level distance=0ex]
    [edge from parent fork down]
    % Children and grandchildren
    child{node[man] {John the\\Conqueror}}
    child{node[man] {Ivan the\\Terrible}}
    child {node[woman] {Joanne\\of Arc}}
    child {node[man] {Richard\\Lionheart}}
    child {node[woman]{Mata\\Hari}};
\end{tikzpicture}
\end{center}
\end{frame}

\end{document}
family-tree.png
family-tree.png (12.55 KiB) Viewed 5534 times
Stefan
LaTeX.org admin
Post Reply