# Overcome 'Dimension too large' when using the forest package with a lot of nodes

I am drawing a genealogical tree with the forest package in which I have approximately 50 nodes. I have reached a point where I get the message "Dimension too large" when I try to add another node.

I have read this and this, which give me an appreciation of the origins of the error, but not much help into what I can do to resolve it.

I am including the tex below; apologies for its length, but I only get an error when I have so many entries. Uncommenting one of the entries will give you the error. The original code was taken from the answer of this question and the Helvet Neue fonts required can be found here.

\documentclass{standalone}
\usepackage{tabularx}
\usepackage{forest}
\usepackage{marvosym}
\usetikzlibrary{shapes.geometric}

\definecolor{color1}{HTML}{FFFFFF}
\definecolor{color2}{HTML}{FFFFFF}

\newcommand\Person[8]{%
{\textbf{#1}} \\
\begin{tabular}{cl}
b: & #2 \\
d: & #3 \\
& #4 \\
\end{tabular} \\
{\textbf{#5}} \\
\begin{tabular}{cl}
b: & #6 \\
d: & #7 \\
& #8 \\
\end{tabular}
}

\newcommand\SinglePerson[4]{%
{\textbf{#1}} \\
\begin{tabular}{cl}
b: & #2 \\
d: & #3 \\
& #4 \\
\end{tabular}
}

\begin{document}

\begin{forest}
delay={
for tree={
edge path={
\noexpand\path[\forestoption{edge}]
([xshift=-(6pt-1pt*level)].child anchor) to[out=180,in=0]
([xshift=(6pt-1pt*level)]!u.parent anchor)\forestoption{edge label};
},
if n=1
{fill=color1,shape=tape,tape bend bottom=none}
{if n'=1
{fill=color2,shape=tape,tape bend top=none}
{}
}
}
},
for tree={
line width=3pt,
inner sep=4pt,
draw=brown,
minimum size=1cm,
text width=4.5cm,
child anchor=west,
parent anchor=east,
grow=east,
l sep=8cm,
s sep=10pt,
draw,
anchor=west,
edge={line width=(18pt-3pt*level),line cap=rect,color=brown},
}
[\Person{L----}{}{}{}{}{}{}{}
[\Person{K----}{}{}{}{M----}{}{}{}
[\Person{P----}{}{}{}{A----}{}{}{}
[\Person{M----}{}{}{}{}{}{}{}]
[\Person{M----}{}{}{}{}{}{}{}]
[\Person{P----}{}{}{}{}{}{}{}]
[\Person{K----}{}{}{}{}{}{}{}]
[\Person{T----}{}{}{}{}{}{}{}]
[\Person{E----}{}{}{}{}{}{}{}]
]
[\Person{L----}{}{}{}{E----}{}{}{}
[\Person{M----}{}{}{}{}{}{}{}]
%[\Person{E----}{}{}{}{}{}{}{}]
%[\Person{K----}{}{}{}{}{}{}{}]
%[\Person{S----}{}{}{}{}{}{}{}]
%[\Person{M----}{}{}{}{}{}{}{}]
%[\Person{A----}{}{}{}{}{}{}{}]
]
[\Person{K----}{}{}{}{}{}{}{}
%[\Person{A----}{}{}{}{}{}{}{}]
%[\Person{T----}{}{}{}{}{}{}{}]
[\Person{G----}{}{}{}{}{}{}{}]
]
[\Person{N----}{}{}{}{F----}{}{}{}
[\Person{M----}{}{}{}{}{}{}{}]
]
[\Person{C----}{}{}{K----}{}{}{}{}
[\Person{A----}{}{}{}{}{}{}{}]
[\Person{G----}{}{}{}{}{}{}{}]
]
[\Person{T----}{}{}{}{E----}{}{}{}
[\Person{M----}{}{}{}{}{}{}{}]
[\Person{E----}{}{}{}{}{}{}{}]
[\Person{K----}{}{}{}{}{}{}{}]
]
[\Person{E----}{}{}{}{A----}{}{}{} ]
[\Person{S----}{ABT 1896-1900}{}{}{C----}{1890}{}{}
[\Person{M----}{1918}{}{}{}{}{}{} ]
[\Person{P----}{13 Mar 1922}{}{}{}{}{}{} ]
[\Person{G---- \Gentsroom}{7 Nov 1925}{--}{}{A---- \Ladiesroom}{17 Dec 1923}{--}{},fill=color2
[\Person{C----}{20 Oct 1950}{}{}{S---- \Gentsroom}{}{}{}
[\Person{G---- \Gentsroom}{21 Nov 1980}{}{}{M----}{}{}{}
]
[\Person{G---- \Gentsroom}{2 Dec 1982}{}{}{M----}{}{}{}
]
]
[\Person{S---- \Gentsroom}{15 Jan 1953}{--}{}{K----}{}{--}{}
[\Person{T----}{}{--}{}{T---- \Gentsroom}{}{--}{}
[\SinglePerson{K----}{}{--}{}
]
]
[\SinglePerson{T---- \Gentsroom}{}{--}{}
]
[\SinglePerson{R----}{}{--}{}
]
][\Person{A----}{}{--}{}{D---- \Gentsroom}{}{--}{}
[\SinglePerson{S---- \Gentsroom}{}{--}{}
]
[\Person{G---- \Gentsroom}{}{--}{}{A----}{}{--}{}
[\SinglePerson{A----}{}{--}{}
]
[\SinglePerson{D---- \Gentsroom}{}{--}{}
]
]
[\SinglePerson{N----}{}{}{Tseri, Nicosia}
]
]
[\Person{M----}{13 Feb 1960}{--}{}{N---- \Gentsroom}{8 Jul 1958}{--}{}
[\Person{N----}{19 Nov 1987}{--}{}{C---- \Gentsroom}{}{--}{}
]
[\SinglePerson{D---- \Gentsroom}{4 Dec 1989}{--}{}
]
[\SinglePerson{C----}{22 May 1995}{--}{}
]
]
]
[\Person{M----}{1928}{}{}{}{}{}{} ]
]
[\Person{G----}{}{}{}{E----}{}{}{}
[\Person{A----}{}{}{}{}{}{}{}]
[\Person{K----}{}{}{}{}{}{}{}]
]
[\Person{M----}{}{}{}{}{}{}{}
[\Person{A----}{}{}{}{}{}{}{}]
[\Person{E----}{}{}{}{}{}{}{}]
]
]
]
\end{forest}

\end{document}

Any ideas on how to resolve this?

• Is using a different font an option? (I assume you wouldn't expect people to obtain special fonts to compile your MWE unless doing so was necessary. So I take it you don't see the problem with standard fonts, for example.) – cfr Jul 23 '14 at 0:11
• @cfr I hadn't thought of changing the font. I have tried it again with the standard fonts (see edit) and the problem is the same. Thanks for the suggestion. – Mitsarien Jul 23 '14 at 7:46
• Thanks. I got errors running this code, by the way (even after changing the fonts). The \definecolor lines caused errors concerning the use of an unknown model or driver so I ended up doing \colorlet... instead. Any idea why? – cfr Jul 23 '14 at 11:03

The problem is not the final size of the document (which is big, but below TeX's \maxdimen). Instead, some internal calculations made by forest exceed temporally this max dimension. Also, the problem persists even if you \usetikzlibrary{fpu} so it is not related to floating point errors.

Thus, the only solution I can find is to use a smaller font and rewrite accordingly some of the edge styles, distances, etc. This way, the whole document will be smaller and thus it will not trigger the maxdimen overflow. If the sizes and distances are wisely chosen, the aspect of the document will not change, because after all you are using standalone package and the resulting pdf can be rescaled again to the desired original size.

So, for example, this is the result of your sample document (with extra nodes commented out so that the document is compilable):

This is a detail of the central zone:

By default, the document uses 10pt fonts, so the following code changes it to 5pt and multiplies by 0.5 all "hardcoded" dimensions in styles:

\documentclass{standalone}
\usepackage{times}
\usepackage{tabularx}
\usepackage{forest}
\usepackage{marvosym}
\usetikzlibrary{shapes.geometric}

\definecolor{color1}{HTML}{FFFFFF}
\definecolor{color2}{HTML}{FFFFFF}

\newcommand\Person[8]{%
{\textbf{#1}} \\
\begin{tabular}{cl}
b: & #2 \\
d: & #3 \\
& #4 \\
\end{tabular} \\
{\textbf{#5}} \\
\begin{tabular}{cl}
b: & #6 \\
d: & #7 \\
& #8 \\
\end{tabular}
}

\newcommand\SinglePerson[4]{%
{\textbf{#1}} \\
\begin{tabular}{cl}
b: & #2 \\
d: & #3 \\
& #4 \\
\end{tabular}
}

\begin{document}\fontsize{5pt}{6pt}

\begin{forest}
delay={
for tree={
edge path={
\noexpand\path[\forestoption{edge}]
([xshift=-(3pt-.5pt*level)].child anchor) to[out=180,in=0]
([xshift=(3pt-.5pt*level)]!u.parent anchor)\forestoption{edge label};
},
if n=1
{fill=color1,shape=tape,tape bend bottom=none}
{if n'=1
{fill=color2,shape=tape,tape bend top=none}
{}
}
}
},
for tree={
line width=1.5pt,
inner sep=2pt,
draw=brown,
minimum size=.5cm,
text width=2.25cm,
child anchor=west,
parent anchor=east,
grow=east,
l sep=4cm,
s sep=5pt,
draw,
anchor=west,
edge={line width=(9pt-1.5pt*level),line cap=rect,color=brown},
}
[\Person{L----}{}{}{}{}{}{}{}
[\Person{K----}{}{}{}{M----}{}{}{}
[\Person{P----}{}{}{}{A----}{}{}{}
[\Person{M----}{}{}{}{}{}{}{}]
[\Person{M----}{}{}{}{}{}{}{}]
[\Person{P----}{}{}{}{}{}{}{}]
[\Person{K----}{}{}{}{}{}{}{}]
[\Person{T----}{}{}{}{}{}{}{}]
[\Person{E----}{}{}{}{}{}{}{}]
]
[\Person{L----}{}{}{}{E----}{}{}{}
[\Person{M----}{}{}{}{}{}{}{}]
[\Person{E----}{}{}{}{}{}{}{}]
[\Person{K----}{}{}{}{}{}{}{}]
[\Person{S----}{}{}{}{}{}{}{}]
[\Person{M----}{}{}{}{}{}{}{}]
[\Person{A----}{}{}{}{}{}{}{}]
]
[\Person{K----}{}{}{}{}{}{}{}
[\Person{A----}{}{}{}{}{}{}{}]
[\Person{T----}{}{}{}{}{}{}{}]
[\Person{G----}{}{}{}{}{}{}{}]
]
[\Person{N----}{}{}{}{F----}{}{}{}
[\Person{M----}{}{}{}{}{}{}{}]
]
[\Person{C----}{}{}{K----}{}{}{}{}
[\Person{A----}{}{}{}{}{}{}{}]
[\Person{G----}{}{}{}{}{}{}{}]
]
[\Person{T----}{}{}{}{E----}{}{}{}
[\Person{M----}{}{}{}{}{}{}{}]
[\Person{E----}{}{}{}{}{}{}{}]
[\Person{K----}{}{}{}{}{}{}{}]
]
[\Person{E----}{}{}{}{A----}{}{}{} ]
[\Person{S----}{ABT 1896-1900}{}{}{C----}{1890}{}{}
[\Person{M----}{1918}{}{}{}{}{}{} ]
[\Person{P----}{13 Mar 1922}{}{}{}{}{}{} ]
[\Person{G---- \Gentsroom}{7 Nov 1925}{--}{}{A---- \Ladiesroom}{17 Dec 1923}{--}{},fill=color2
[\Person{C----}{20 Oct 1950}{}{}{S---- \Gentsroom}{}{}{}
[\Person{G---- \Gentsroom}{21 Nov 1980}{}{}{M----}{}{}{}
]
[\Person{G---- \Gentsroom}{2 Dec 1982}{}{}{M----}{}{}{}
]
]
[\Person{S---- \Gentsroom}{15 Jan 1953}{--}{}{K----}{}{--}{}
[\Person{T----}{}{--}{}{T---- \Gentsroom}{}{--}{}
[\SinglePerson{K----}{}{--}{}
]
]
[\SinglePerson{T---- \Gentsroom}{}{--}{}
]
[\SinglePerson{R----}{}{--}{}
]
][\Person{A----}{}{--}{}{D---- \Gentsroom}{}{--}{}
[\SinglePerson{S---- \Gentsroom}{}{--}{}
]
[\Person{G---- \Gentsroom}{}{--}{}{A----}{}{--}{}
[\SinglePerson{A----}{}{--}{}
]
[\SinglePerson{D---- \Gentsroom}{}{--}{}
]
]
[\SinglePerson{N----}{}{}{Tseri, Nicosia}
]
]
[\Person{M----}{13 Feb 1960}{--}{}{N---- \Gentsroom}{8 Jul 1958}{--}{}
[\Person{N----}{19 Nov 1987}{--}{}{C---- \Gentsroom}{}{--}{}
]
[\SinglePerson{D---- \Gentsroom}{4 Dec 1989}{--}{}
]
[\SinglePerson{C----}{22 May 1995}{--}{}
]
]
]
[\Person{M----}{1928}{}{}{}{}{}{} ]
]
[\Person{G----}{}{}{}{E----}{}{}{}
[\Person{A----}{}{}{}{}{}{}{}]
[\Person{K----}{}{}{}{}{}{}{}]
]
[\Person{M----}{}{}{}{}{}{}{}
[\Person{A----}{}{}{}{}{}{}{}]
[\Person{E----}{}{}{}{}{}{}{}]
]
]
]
\end{forest}

\end{document}

The extra nodes are uncommented, and thus included in the final image, which compiles without errors and produces:

Zooming into the central part, we can see almost no difference with the first document:

Note: I changed the main font to times, because this font has the same shape at any size. Computer modern, instead, uses different shapes for smaller fonts which are wider once rescaled back.

• Nice except that times is obsolete and ought not be used for Times. – cfr Mar 29 '18 at 20:00