0

I have the following tree produced by the LaTeX code at the end, which is a modification from Drawing a directory listing a la the tree command in TikZ

My problem: When I have a lot of nodes, I get Dimension too large error, as shown in the second picture. I saw something like \pgfkeys{/pgf/fpu=true}, but I can't make it work in my code. I need help to allow any number of nodes other than reducing the size of each node and the distances between them.

enter image description here

enter image description here

\documentclass{standalone}
\usepackage[english, french]{babel}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usepackage{hyperref}
\usepackage{amsmath}


\makeatletter
\newcount\dirtree@lvl
\newcount\dirtree@plvl
\newcount\dirtree@clvl
\def\dirtree@growth{%
    \ifnum\tikznumberofcurrentchild=1\relax
    \global\advance\dirtree@plvl by 1
    \expandafter\xdef\csname dirtree@p@\the\dirtree@plvl\endcsname{\the\dirtree@lvl}
    \fi
    \global\advance\dirtree@lvl by 1\relax
    \dirtree@clvl=\dirtree@lvl
    \advance\dirtree@clvl by -\csname dirtree@p@\the\dirtree@plvl\endcsname
    \pgf@xa=1.15cm\relax
    \pgf@ya=-1.45cm\relax
    \pgf@ya=\dirtree@clvl\pgf@ya
    \pgftransformshift{\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}%
    \ifnum\tikznumberofcurrentchild=\tikznumberofchildren
    \global\advance\dirtree@plvl by -1
    \fi
}

\tikzset{
    dirtree/.style={
        growth function=\dirtree@growth,
        every node/.style={anchor=south},
        every child node/.style={anchor=west},
        edge from parent path={(\tikzparentnode\tikzparentanchor) |- (\tikzchildnode\tikzchildanchor)}
    }
}
\makeatother

\makeatletter
\newcommand*\mylabel[2]{%
    \immediate\write\@auxout{\string\newlabel%
        \string{#1\string}%
        \string{\string{#2\string}%
            \string{\thepage\string}\string}}%
}
\makeatother

\makeatletter


\begin{document}


    \begin{tikzpicture}[dirtree, event/.style={rectangle,thick,draw,fill=yellow!20,
        anchor=south}, level 1/.style={nodes=event}, line width=0.75mm]

\node[event] {Master}
child { node {1}
child { node {1-1}
}
child { node {1-2}
}
}
child { node {2}
child { node {2-1}
}
child { node {2-2}
}
}
;
\end{tikzpicture}
\end{document}

Update: Zarko's answer (forest) doesn't help me:

enter image description here

user565739
  • 5,482
  • There are four answers in this question, if this one fails, did you tried with some other? I think forest is a better option for trees. – Ignasi Mar 22 '18 at 14:50
  • Have you tried using forest and compiling with lualatex? It dynamically allocates memory and is less likely to give out of memory errors. – Hood Chatham Mar 23 '18 at 22:25
  • Also, could you give an example where the out of memory error actually occurs? The example you've given isn't big enough. – Hood Chatham Mar 23 '18 at 22:27
  • Change pgf@ya to -145cm will produce the same problem – user565739 Mar 23 '18 at 22:30
  • It's not the problem of number of node, it's the huge content can't be fit in the document – user565739 Mar 23 '18 at 22:31
  • Forest will make especially compact trees, so likely allow more nodes. However, no solution will allow you to exceed the maximum dimension TeX can cope with - not even LuaTeX, which will avoid many out-of-memory problems. That is, you can avoid the memory limit (using LuaTeX or in other ways) but if you are talking about producing pages with huge dimensions (as mentioned in the comments on Zarko's answer), then you're out of luck. The limit is hard-wired into TeX. – cfr Mar 29 '18 at 19:59
  • Note that Zarko's answer may help. The key is that the error is different: unlike code which exceeds the maximum dimension, the maximum save size can be altered. See egreg's comment at https://tex.stackexchange.com/questions/234095/forest-causing-pdflatex-to-run-out-of-memory#comment554612_234095. – cfr Mar 29 '18 at 20:05
  • Note that, as @Ignasi pointed out, there are multiple answers to the question you linked, so just trying the first one isn't always the best strategy. This is especially true if some answers are much newer than those at the top: they may have fewer votes because posted much later, but use newer packages which solve problems in simpler or more flexible ways. Or they may have fewer votes because they are poorer answers, of course. You have to read them, try things which seem promising and see - especially since there's rarely a one-size-fits-all solution. But arbitrarily-large cannot be done. – cfr Mar 29 '18 at 20:15

0 Answers0