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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.