4

In the previous question Large Quantity of Nodes Result in Overlap, I, foolishly, tried to create a tree using Nodes. That approach resulted in overlapping nodes as the tree got larger. User Ignasi recommended I use Tikz-trees instead.

Here, I have switched over to using tikz trees and the same problem is encountered. Please have a look at the screen shot and try out the MWE (compiled using pdflatex) and please advise as to how I can get around this.

EDIT Included screenshot and MWE

enter image description here

\documentclass{article}

\usepackage{tikz}
\usepackage{adjustbox}     %shrink Tikz or figures
\usepackage{pdflscape}     %landscape Tikz image
\usetikzlibrary{positioning,shadows,shapes,arrows}

\begin{document}

\begin{landscape}
\begin{center}
\begin{adjustbox}{max size={\textwidth}{\textheight}}
\begin{tikzpicture}[sibling distance=10em, every node/.style = {shape=rectangle, rounded corners, draw, align=center, top color=white, bottom color=blue!20}]

\node {Blablabla}
   child { node {Blablabla} }
   child { node {Blablabla} }
   child { node {Blablabla}
      child { node {Blablabla} }
      child { node {Blablabla} }
      child { node {Blablabla}
         child { node {Blablabla}
            child { node {Blablabla} }
            child { node {Blablabla} }
            child { node {Blablabla}
               child { node {Blablabla} 
                  child { node {Blablabla}
                     child { node {Blablabla} }
                  }
               }
               child { node {Blablabla}
                  child { node {Blablabla} }
               }
            }
            child { node {Blablabla}
               child { node {Blablabla} }
            }
         }
         child { node {Blablabla}
            child { node {Blablabla}
               child { node {Blablabla} }
               child { node {Blablabla} }
               child { node {Blablabla} 
                  child { node {Blablabla}
                     child { node {Blablabla} }
                     child { node {Blablabla} }
                  }
                  child { node {Blablabla}
                     child { node {Blablabla}
                        child { node {Blablabla}
                           child { node {Blablabla}}}}}}}}}};

\end{tikzpicture}
\end{adjustbox}
\end{center}
\end{landscape}
\end{document}

EDIT: Picture 2 Here is a screenshot with unique text, to more easily distinguish how the nodes are arranged

enter image description here

EDIT: MWE 2 Here is the new Minimum Working Example showing the unique text

\documentclass{article}

\usepackage{tikz}
\usepackage{adjustbox}     %shrink Tikz or figures
\usepackage{pdflscape}     %landscape Tikz image
\usetikzlibrary{positioning,shadows,shapes,arrows}

\begin{document}

\begin{landscape}
\begin{center}
\begin{adjustbox}{max size={\textwidth}{\textheight}}
\begin{tikzpicture}[sibling distance=10em, every node/.style = {shape=rectangle, rounded corners, draw, align=center, top color=white, bottom color=blue!20}]

\node {Blablabla1}
   child { node {Blablabla2} }
   child { node {Blablabla3} }
   child { node {Blablabla4}
      child { node {Blablabla5} }
      child { node {Blablabla6} }
      child { node {Blablabla7}
         child { node {Blablabla8}
            child { node {Blablabla9} }
            child { node {Blablabla10} }
            child { node {Blablabla11}
               child { node {Blablabla12} 
                  child { node {Blablabla13}
                     child { node {Blablabla14} }
                  }
               }
               child { node {Blablabla15}
                  child { node {Blablabla16} }
               }
            }
            child { node {Blablabla17}
               child { node {Blablabla18} }
            }
         }
         child { node {Blablabla19}
            child { node {Blablabla20}
               child { node {Blablabla21} }
               child { node {Blablabla22} }
               child { node {Blablabla23} 
                  child { node {Blablabla24}
                     child { node {Blablabla25} }
                     child { node {Blablabla26} }
                  }
                  child { node {Blablabla27}
                     child { node {Blablabla28}
                        child { node {Blablabla29}
                           child { node {Blablabla30}}}}}}}}}};

\end{tikzpicture}
\end{adjustbox}
\end{center}
\end{landscape}
\end{document}
6
  • @egreg I forgot to include them the first time
    – puk
    Apr 19, 2016 at 21:13
  • What's overlapping? It is difficult to really tell since every node has identical content anyway.
    – cfr
    Apr 19, 2016 at 21:15
  • @cfr I could change it so they have numbers (ie. "Blablabla1") but that's besides the point, IMO. The issue is that there is at least one case of overlap. Agree/disagree?
    – puk
    Apr 19, 2016 at 21:17
  • Well, no. I can't tell. That's my point. I can't tell which node is overlapping with which other. I can see that some edges cross other edges, but that's not nodes.
    – cfr
    Apr 19, 2016 at 21:25
  • 1
    OK. Thanks, that's helpful. I definitely recommend forest. See my answer below. Forest will just make it so things don't overlap out-of-the-box, saving you the trouble of ensuring this. Forest is good at this. Or you could, I guess, use the graph-drawing stuff based on LuaTeX. But it seems as if you know the basic structure you want and just the spacing/positioning is the issue. If that's so, Forest is almost certainly the best option.
    – cfr
    Apr 19, 2016 at 21:38

1 Answer 1

6

Forest is especially good at drawing compact trees and at automatically arranging the tree so that nodes and edges do not (in the vast majority of cases) collide. Of course, it will not magically make large things fit into small boxes, but it will make sure that large things begin in sufficiently large boxes.

For example:

\documentclass[border=10pt,tikz,multi]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
  for tree={
    rounded corners,
    draw,
    align=center,
    top color=white,
    bottom color=blue!20,
  },
  forked edges,
  [a
    [b]
    [c]
    [d
      [e]
      [f]
      [g
        [h
          [j]
          [k]
          [l]
          [m[y][z]]
        ]
        [i
          [n
           [h
            [j]
            [k]
            [l]
            [m[y][z]]
          ]
         ]
          [o
            [q
              [h
                [j]
                [k]
                [l]
                [m[y][z]]
              ]
            ]
            [r[s[t[u
              [v]
              [w]
              [x]
            ]]]]
          ]
          [p
            [q[u
              [v]
              [w]
              [x]
            ]]
            [r[s[t[u
              [v]
              [w]
              [x]
            ]]]]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\end{document}

compact tree

Or, for the same structure but node content from the sample text in the question:

compact tree with less concise nodes

\begin{forest}
  for tree={
    rounded corners,
    draw,
    align=center,
    top color=white,
    bottom color=blue!20,
  },
  forked edges,
  [Blablabla
    [Blablabla]
    [Blablabla]
    [Blablabla
      [Blablabla]
      [Blablabla]
      [Blablabla
        [Blablabla
          [Blablabla]
          [Blablabla]
          [Blablabla]
          [Blablabla[Blablabla][Blablabla]]
        ]
        [Blablabla
          [Blablabla
           [Blablabla
            [Blablabla]
            [Blablabla]
            [Blablabla]
            [Blablabla[Blablabla][Blablabla]]
          ]
         ]
          [Blablabla
            [Blablabla
              [Blablabla
                [Blablabla]
                [Blablabla]
                [Blablabla]
                [Blablabla[Blablabla][Blablabla]]
              ]
            ]
            [Blablabla[Blablabla[Blablabla[Blablabla
              [Blablabla]
              [Blablabla]
              [Blablabla]
            ]]]]
          ]
          [Blablabla
            [Blablabla[Blablabla
              [Blablabla]
              [Blablabla]
              [Blablabla]
            ]]
            [Blablabla[Blablabla[Blablabla[Blablabla
              [Blablabla]
              [Blablabla]
              [Blablabla]
            ]]]]
          ]
        ]
      ]
    ]
  ]
\end{forest}

Obviously, you can put this in a scaled box or whatever, even though that is scarcely to be recommended and will probably make the tree unreadable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .