7

I drew a family tree using TikZ with the positioning library, following in the footsteps of Gonzalo.

The problem is that there is a blank page generated before the family tree. Can anyone explain why it is there and how to get rid of it? I've tried fiddling with the code to shrink the tree with no success. I put a bounding box around the figure, but the box is on the same page.

I've left out the connecting edges for brevity. It is still quite long. If necessary I could probably strip it down further, but if I do, this also increases the risk that a fix may not work on the actual example.

@DavidCarlisle suggested the workaround

\setlength{\textheight}{.8\maxdimen}

This suppresses the blank page, but also suppresses any additional pages.

\documentclass{article}
\usepackage{tikz}
\usepackage{standalone}
\usetikzlibrary{positioning}
\setlength{\oddsidemargin}{-0.6in}
\setlength{\evensidemargin}{-0.10in}
\setlength{\topmargin}{-0.5in}
\setlength{\headsep}{0.0in}
\pagenumbering{gobble}
\begin{document}

\tikzset{
every node/.style={rectangle,draw,minimum height=3em,text width=2.0cm},
female/.style = {fill=red!20, rounded corners},
male/.style = {fill=blue!20},
neutral/.style = {fill=green!20}
}
\begin{tikzpicture}[node distance=8pt and 33pt]

% GEN 1

\node[female] (Female1) {Female1};
\node[male,below=of Female1] (Male1) {Male1};

% GEN 2

 \node[female,above right=of Female1, yshift=5cm] (Female2) {Female2};
 \node[female,below=of Female2, yshift=-2cm] (Female3) {Female3};
 \node[male,below=of Female3, yshift=-2cm] (Male2) {Male2};
 \node[male,below=of Male2, yshift=-2cm] (Male3) {Male3};
 \node[female,below=of Male3, yshift=-4cm] (Female5) {Female5};

 % % GEN 2 SPOUSES

 \node[male,above=of Female2] (Male4) {Male4};
 \node[male,above=of Female3] (Male5) {Male5};
 \node[male,above=of Male2] (Male2-wife) {Wife};
 \node[female,above=of Male3] (Female6) {Female6};
 \node[male,below=of Female5] (Male6) {Male6};

% GEN 3

 \node[female,above right=of Female2, yshift=4cm] (Female7) {Female7};
 \node[male,below=of Female7, yshift=-1.5cm] (Male7) {Male7};
 \node[female,below=of Male7, yshift=-1cm] (Female8) {Female8};
 \node[male,below=of Female8, yshift=-1cm] (Male8) {Male8};
 \node[male,right=of Female3] (Female9) {Female9};

 \node[female,above right=of Male3, yshift=4cm] (Female10) {Female10};
 \node[female,below=of Female10, yshift=-3cm] (Female11) {Female11};
 \node[male,below=of Female11, yshift=-1.5cm] (Male9) {Male9};
 \node[male,below=of Male9, yshift=-0.5cm] (Male10) {Male10};

 \node[male,right=of Male6] (Male11) {Male11};

 % GEN 3 SPOUSES

 \node[male,above=of Female7] (Male12) {Male12};
 \node[male,below=of Female7] (Female7-husband) {husband};
 \node[male,below=of Female10] (Male13) {Male13};
 \node[male,above=of Female11] (Male14) {Male14};
 \node[male,below=of Female11] (Male15) {Male15};
 \node[female,below=of Male10] (Female12) {Female12};

% GEN 4

 \node[female,right=of Male12] (Female7-daughter1) {daughter};
 \node[female,below=of Female7-daughter1] (Female7-daughter2) {daughter};
 \node[male,right=of Female9, yshift=0.5cm] (Male16) {Male16};
 \node[male,right=of Female10, yshift=0.5cm] (Male17) {Male17};
 \node[female,below=of Male17] (Female18) {Female18};
 \node[male,right=of Male14, yshift=1cm] (Male18) {Male18};
 \node[female,right=of Female11, yshift=0.1cm] (Female19) {Female19};
 \node[male,right=of Male15] (Male19) {Male19};
 \node[female,right=of Male10, yshift=0.5cm] (Female20) {Female20};
 \node[male,below=of Female20] (Male20) {Male20};

 % GEN 5

 \node[male,right=of Male20, yshift=1cm] (Male20-son1) {son};
 \node[male,below=of Male20-son1] (Male20-son2) {son};
 \node[male,below=of Male20-son2] (Male20-son3) {son};
 \node[female,below=of Male20-son3] (Male20-daughter1) {daughter};

\end{tikzpicture}
\end{document}

UPDATE:

Thanks to Harish and Gonzalo for the solutions. They both work, and it was difficult to pick one, but I liked the simplicity of \usepackage[a4paper,margin=1in]{geometry}, so I'm currently using that.

Faheem Mitha
  • 7,778

2 Answers2

6

Your tikzpicture is too big to fit in the page vertically. LaTeX tries its best to fit it in the first page and throws the error:

Overfull \vbox (147.53874pt too high) has occurred while \output is active

Being unsuccessful, it pushes the picture to the second page leaving first one empty.

What to do? Make the first page bit bigger using geometry:

\documentclass{article}
\usepackage{tikz}
\usepackage{standalone}
\usetikzlibrary{positioning}
%\setlength{\oddsidemargin}{-0.6in}
%\setlength{\evensidemargin}{-0.10in}
%\setlength{\topmargin}{-0.5in}
%\setlength{\headsep}{0.0in}
\pagenumbering{gobble}
\usepackage[a4paper,margin=1in]{geometry}    %%% this line added.
\begin{document}    
\tikzset{
every node/.style={rectangle,draw,minimum height=3em,text width=2.0cm},
female/.style = {fill=red!20, rounded corners},
male/.style = {fill=blue!20},
neutral/.style = {fill=green!20}
}
\noindent
\begin{tikzpicture}[node distance=8pt and 33pt]
% GEN 1
\node[female] (Female1) {Female1};
\node[male,below=of Female1] (Male1) {Male1};
% GEN 2
 \node[female,above right=of Female1, yshift=5cm] (Female2) {Female2};
 \node[female,below=of Female2, yshift=-2cm] (Female3) {Female3};
 \node[male,below=of Female3, yshift=-2cm] (Male2) {Male2};
 \node[male,below=of Male2, yshift=-2cm] (Male3) {Male3};
 \node[female,below=of Male3, yshift=-4cm] (Female5) {Female5};
 % % GEN 2 SPOUSES
 \node[male,above=of Female2] (Male4) {Male4};
 \node[male,above=of Female3] (Male5) {Male5};
 \node[male,above=of Male2] (Male2-wife) {Wife};
 \node[female,above=of Male3] (Female6) {Female6};
 \node[male,below=of Female5] (Male6) {Male6};
% GEN 3
 \node[female,above right=of Female2, yshift=4cm] (Female7) {Female7};
 \node[male,below=of Female7, yshift=-1.5cm] (Male7) {Male7};
 \node[female,below=of Male7, yshift=-1cm] (Female8) {Female8};
 \node[male,below=of Female8, yshift=-1cm] (Male8) {Male8};
 \node[male,right=of Female3] (Female9) {Female9};
 \node[female,above right=of Male3, yshift=4cm] (Female10) {Female10};
 \node[female,below=of Female10, yshift=-3cm] (Female11) {Female11};
 \node[male,below=of Female11, yshift=-1.5cm] (Male9) {Male9};
 \node[male,below=of Male9, yshift=-0.5cm] (Male10) {Male10};
 \node[male,right=of Male6] (Male11) {Male11};
 % GEN 3 SPOUSES
 \node[male,above=of Female7] (Male12) {Male12};
 \node[male,below=of Female7] (Female7-husband) {husband};
 \node[male,below=of Female10] (Male13) {Male13};
 \node[male,above=of Female11] (Male14) {Male14};
 \node[male,below=of Female11] (Male15) {Male15};
 \node[female,below=of Male10] (Female12) {Female12};
% GEN 4
 \node[female,right=of Male12] (Female7-daughter1) {daughter};
 \node[female,below=of Female7-daughter1] (Female7-daughter2) {daughter};
 \node[male,right=of Female9, yshift=0.5cm] (Male16) {Male16};
 \node[male,right=of Female10, yshift=0.5cm] (Male17) {Male17};
 \node[female,below=of Male17] (Female18) {Female18};
 \node[male,right=of Male14, yshift=1cm] (Male18) {Male18};
 \node[female,right=of Female11, yshift=0.1cm] (Female19) {Female19};
 \node[male,right=of Male15] (Male19) {Male19};
 \node[female,right=of Male10, yshift=0.5cm] (Female20) {Female20};
 \node[male,below=of Female20] (Male20) {Male20};
\end{tikzpicture}
\end{document}

enter image description here

The options [a4paper,margin=1in] provide a bigger paper than the default. Hence the picture fits in.

Or you can use standalone class directly to get the picture.

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{positioning}
\tikzset{
every node/.style={rectangle,draw,minimum height=3em,text width=2.0cm},
female/.style = {fill=red!20, rounded corners},
male/.style = {fill=blue!20},
neutral/.style = {fill=green!20}
}
\begin{document}
\begin{tikzpicture}[node distance=8pt and 33pt]
% GEN 1
\node[female] (Female1) {Female1};
\node[male,below=of Female1] (Male1) {Male1};
% GEN 2
 \node[female,above right=of Female1, yshift=5cm] (Female2) {Female2};
 \node[female,below=of Female2, yshift=-2cm] (Female3) {Female3};
 \node[male,below=of Female3, yshift=-2cm] (Male2) {Male2};
 \node[male,below=of Male2, yshift=-2cm] (Male3) {Male3};
 \node[female,below=of Male3, yshift=-4cm] (Female5) {Female5};
 % % GEN 2 SPOUSES
 \node[male,above=of Female2] (Male4) {Male4};
 \node[male,above=of Female3] (Male5) {Male5};
 \node[male,above=of Male2] (Male2-wife) {Wife};
 \node[female,above=of Male3] (Female6) {Female6};
 \node[male,below=of Female5] (Male6) {Male6};
% GEN 3
 \node[female,above right=of Female2, yshift=4cm] (Female7) {Female7};
 \node[male,below=of Female7, yshift=-1.5cm] (Male7) {Male7};
 \node[female,below=of Male7, yshift=-1cm] (Female8) {Female8};
 \node[male,below=of Female8, yshift=-1cm] (Male8) {Male8};
 \node[male,right=of Female3] (Female9) {Female9};
 \node[female,above right=of Male3, yshift=4cm] (Female10) {Female10};
 \node[female,below=of Female10, yshift=-3cm] (Female11) {Female11};
 \node[male,below=of Female11, yshift=-1.5cm] (Male9) {Male9};
 \node[male,below=of Male9, yshift=-0.5cm] (Male10) {Male10};
 \node[male,right=of Male6] (Male11) {Male11};
 % GEN 3 SPOUSES
 \node[male,above=of Female7] (Male12) {Male12};
 \node[male,below=of Female7] (Female7-husband) {husband};
 \node[male,below=of Female10] (Male13) {Male13};
 \node[male,above=of Female11] (Male14) {Male14};
 \node[male,below=of Female11] (Male15) {Male15};
 \node[female,below=of Male10] (Female12) {Female12};
% GEN 4
 \node[female,right=of Male12] (Female7-daughter1) {daughter};
 \node[female,below=of Female7-daughter1] (Female7-daughter2) {daughter};
 \node[male,right=of Female9, yshift=0.5cm] (Male16) {Male16};
 \node[male,right=of Female10, yshift=0.5cm] (Male17) {Male17};
 \node[female,below=of Male17] (Female18) {Female18};
 \node[male,right=of Male14, yshift=1cm] (Male18) {Male18};
 \node[female,right=of Female11, yshift=0.1cm] (Female19) {Female19};
 \node[male,right=of Male15] (Male19) {Male19};
 \node[female,right=of Male10, yshift=0.5cm] (Female20) {Female20};
 \node[male,below=of Female20] (Male20) {Male20};
\end{tikzpicture}
\end{document}
  • That works, thanks. However, can you elaborate on how this works. I tried adjusting the top margin myself, but that didn't make any difference. By setting \setlength{\topmargin}{-0.5in} and trying different values. From the docs, it looks like \usepackage[a4paper,margin=1in]{geometry} makes all margins 1 in. Is that right? Also, how could I use standalone directly, and would it cut off later pages? – Faheem Mitha Feb 09 '14 at 15:34
  • @FaheemMitha a4paper is longer than letterpaper. –  Feb 09 '14 at 16:17
  • I thought I was using letterpaper. – Faheem Mitha Feb 09 '14 at 16:23
  • Something I don't understand: You wrote "LaTeX tries its best to fit it in the first page and throws the error:" [snip] "Being unsuccessful, it pushes the picture to the second page leaving first one empty." But I don't see why the second page is a better fit than the first page. By this logic, shouldn't it keep pushing the figure forward ad-infinitum? – Faheem Mitha Feb 09 '14 at 16:43
  • @FaheemMitha It won't push infinitely but the next page with lot of mis-alignments. –  Feb 09 '14 at 16:47
  • OK, but I don't see the logic to this. – Faheem Mitha Feb 09 '14 at 16:49
  • Hi Harish. For the version using standalone, namely \documentclass[tikz,border=5pt]{standalone}, the left side of the picture gets cut off, for both my original and revised version. – Faheem Mitha Feb 09 '14 at 21:18
  • @FaheemMitha Strange, I get it right. I will add a screen shot. Can you increase the left border? \documentclass[tikz,border={10pt 5pt 5pt 5pt},preview]{standalone} –  Feb 09 '14 at 22:46
  • I tried the version you posted, and it worked. My version had a bunch of other stuff which you had taken out, like the calls to \setlength. Sorry for the confusion. – Faheem Mitha Feb 10 '14 at 08:06
3

Besides the vertical problem, there's also an overful \hbox since the figure is too wide and you forgot tu suppress indentation with a \noindent. You can also solve these problems, without using additional packages by hiding the width, height and depth of the figure using \raisebox and \makebox:

\documentclass{article}
\usepackage{tikz}
\usepackage{standalone}
\usetikzlibrary{positioning}
\setlength{\oddsidemargin}{-0.6in}
\setlength{\evensidemargin}{-0.10in}
\setlength{\topmargin}{-0.5in}
\setlength{\headsep}{0.0in}
\pagenumbering{gobble}
\begin{document}

\tikzset{
every node/.style={rectangle,draw,minimum height=3em,text width=2.0cm},
female/.style = {fill=red!20, rounded corners},
male/.style = {fill=blue!20},
neutral/.style = {fill=green!20}
}

\noindent\raisebox{-\height}[0pt][0pt]{%
  \makebox[\linewidth][l]{%
\begin{tikzpicture}[node distance=8pt and 33pt]

% GEN 1

\node[female] (Female1) {Female1};
\node[male,below=of Female1] (Male1) {Male1};

% GEN 2

 \node[female,above right=of Female1, yshift=5cm] (Female2) {Female2};
 \node[female,below=of Female2, yshift=-2cm] (Female3) {Female3};
 \node[male,below=of Female3, yshift=-2cm] (Male2) {Male2};
 \node[male,below=of Male2, yshift=-2cm] (Male3) {Male3};
 \node[female,below=of Male3, yshift=-4cm] (Female5) {Female5};

 % % GEN 2 SPOUSES

 \node[male,above=of Female2] (Male4) {Male4};
 \node[male,above=of Female3] (Male5) {Male5};
 \node[male,above=of Male2] (Male2-wife) {Wife};
 \node[female,above=of Male3] (Female6) {Female6};
 \node[male,below=of Female5] (Male6) {Male6};

% GEN 3

 \node[female,above right=of Female2, yshift=4cm] (Female7) {Female7};
 \node[male,below=of Female7, yshift=-1.5cm] (Male7) {Male7};
 \node[female,below=of Male7, yshift=-1cm] (Female8) {Female8};
 \node[male,below=of Female8, yshift=-1cm] (Male8) {Male8};
 \node[male,right=of Female3] (Female9) {Female9};

 \node[female,above right=of Male3, yshift=4cm] (Female10) {Female10};
 \node[female,below=of Female10, yshift=-3cm] (Female11) {Female11};
 \node[male,below=of Female11, yshift=-1.5cm] (Male9) {Male9};
 \node[male,below=of Male9, yshift=-0.5cm] (Male10) {Male10};

 \node[male,right=of Male6] (Male11) {Male11};

 % GEN 3 SPOUSES

 \node[male,above=of Female7] (Male12) {Male12};
 \node[male,below=of Female7] (Female7-husband) {husband};
 \node[male,below=of Female10] (Male13) {Male13};
 \node[male,above=of Female11] (Male14) {Male14};
 \node[male,below=of Female11] (Male15) {Male15};
 \node[female,below=of Male10] (Female12) {Female12};

% GEN 4

 \node[female,right=of Male12] (Female7-daughter1) {daughter};
 \node[female,below=of Female7-daughter1] (Female7-daughter2) {daughter};
 \node[male,right=of Female9, yshift=0.5cm] (Male16) {Male16};
 \node[male,right=of Female10, yshift=0.5cm] (Male17) {Male17};
 \node[female,below=of Male17] (Female18) {Female18};
 \node[male,right=of Male14, yshift=1cm] (Male18) {Male18};
 \node[female,right=of Female11, yshift=0.1cm] (Female19) {Female19};
 \node[male,right=of Male15] (Male19) {Male19};
 \node[female,right=of Male10, yshift=0.5cm] (Female20) {Female20};
 \node[male,below=of Female20] (Male20) {Male20};

 % GEN 5

 \node[male,right=of Male20, yshift=1cm] (Male20-son1) {son};
 \node[male,below=of Male20-son1] (Male20-son2) {son};
 \node[male,below=of Male20-son2] (Male20-son3) {son};
 \node[female,below=of Male20-son3] (Male20-daughter1) {daughter};

\end{tikzpicture}%
  }%
}

\clearpage
\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Thanks for the answer, Gonzalo. Minor typo: \noindet should be \noindent. I tried your modification on the figure, but the text following the figure (on another page) was then superimposed on the figure, with everything on one page. Should I add some text after my example? – Faheem Mitha Feb 09 '14 at 15:55
  • @FaheemMitha add a \clearpage command; I've added it to my updated answer. – Gonzalo Medina Feb 09 '14 at 15:56
  • Apologies for the nuisance, but I modified my original figure too much, as I figured. My original figure gets pushed off to the left. I've added something to my figure to show the problem. – Faheem Mitha Feb 09 '14 at 16:22
  • @FaheemMitha no need to apologize! :) Please see my updated answer. (change c to l in the specification for \makebox.) – Gonzalo Medina Feb 09 '14 at 16:34
  • That looks good, thanks. Can you elaborate on what "hiding the width, height and depth of the figure" means? Also, another minor typo - "tu" instead of "to". – Faheem Mitha Feb 09 '14 at 16:37
  • @FaheemMitha it means that using the settings for the \raisebox and \makebox the object has been boxed and the box has zero width, height and depth, as far as TeX is concerned, the object has zero width, height and depth; this allow you to place it without problems. – Gonzalo Medina Feb 09 '14 at 16:40
  • I see. I think that is worth mentioning in the answer. So you are tricking TeX into thinking there is nothing there, so it doesn't try to push it somewhere else? – Faheem Mitha Feb 09 '14 at 16:41
  • @FaheemMitha You're right, although there is something there, but it has zero width, depth and height, so it won't exceed the margins and won't be pushed away. – Gonzalo Medina Feb 09 '14 at 16:50