[Tex/LaTex] Tree with six or more children

qtreetrees

I'm using qtree and a tree with five children works perfectly:

\documentclass{standalone}
\usepackage{qtree}

\begin{document}

\Tree[.n 1 2 3 4 5 ]

\end{document}

Tree with 5 children

But when I add another node:

\documentclass{standalone}
\usepackage{qtree}

\begin{document}

\Tree[.n 1 2 3 4 5 6 ]

\end{document}

It prints a single 6. Checking the package documentation (warning: pdf) there seems to be a constraint of 5 children per node, and the reason eludes me.

What is the correct way to build such a tree?

Best Answer

If you do not object to using tikz, you have a number of more flexible options. tikz has a trees library but you will probably prefer something with a brackets-type syntax. tikz-qtree is one option. forest is another.

tikz-qtree

This option lets you keep using just the same syntax as qtree.

\documentclass{standalone}
\usepackage{tikz, tikz-qtree}

\begin{document}

\Tree
  [.n 1 2 3 4 5 6 ]

\end{document}

<code>tikz-qtree</code> tree with 6 children

forest

This option requires you to use a different syntax but it should nonetheless be rather familiar in many respects. The pay-off comes in the form of greater power and flexibility. While that's not needed for this example, it would be worth switching if you have more demanding trees to draw.

\documentclass{standalone}
\usepackage{forest}

\begin{document}

\begin{forest}
  [n
    [1]
    [2]
    [3]
    [4]
    [5]
    [6]
  ]
\end{forest}

\end{document}

<code>forest</code> tree with 6 children

Or perhaps:

\documentclass{standalone}
\usepackage{forest}

\begin{document}

\begin{forest}
  for tree={
    parent anchor=south,
    child anchor=north,
  }
  [n
  [1]
  [3]
  [3]
  [4]
  [5]
  [6]
  ]
\end{forest}

\end{document}

Another <code>forest</code> tree with 6 children

Related Question