4

How can one create a tree structure in LaTeX that begins with a single number and extends with an arbitrary number of arrows that connect numbers below with numbers above such that the head faces upward? For example, a tree of this form:

I see that there are similar trees without directed arrows as shown here. Similarly, I see that there are trees with directed arrows that are not similar as shown here. Is there a way to combine these two elements in tikz?

Is simply copying the following elements from \usepackage{tikz,forest} sufficient or are entirely different elements needed?

\documentclass{article}
\usepackage{tikz,forest}

\begin{document}
\texttt{grow} used in a Ti\textit{k}Z tree

\begin{tikzpicture}
  \node{1}
    child{node{child 1}}
    child[grow=south]{node{child 2}
      child child child
    }
  ;
\end{tikzpicture}
end{forest}
end{document}

enter image description here

Blender
  • 43

2 Answers2

3

You could try the new graphs stuff in the latest PGF with lualatex:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{graphs,graphdrawing,arrows.meta}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}[>=Stealth]    
\graph  [tree layout, grow=down]{
  1 <- 2 <- {
    3 <- {
      5 <- {10,11,12}, 6 <- {13,14}, 7 <- {,15}
    }, 
    4 <- {,/}
  };   
};
\end{tikzpicture}
\end{document} 

enter image description here

Mark Wibrow
  • 70,437
  • If I already have a document with a \documentclass how do I add in this new document class? Simply adding it below the other results in an error. – Blender Oct 03 '14 at 12:26
  • @Blender with another document class (e.g., article) you would just replace the first line in the example above with \documentclass{article} \usepackage{tikz}. – Mark Wibrow Oct 04 '14 at 10:55
3

Here's a forest solution which numbers the nodes automatically:

\documentclass[tikz,border=5pt]{standalone}
\usepackage{forest}

\begin{document}

\bracketset{action character=@}% based on code from page 22 of forest's manual
\newcount\xcount
\def\x{@@\advance\xcount1
  \edef\xtemp{$\noexpand{\the\xcount}$}%
  \expandafter\bracketResume\xtemp
}
\begin{forest}
  delay={%
        content={#1}%
  },
  for tree={%
    edge path={
      \noexpand\path[<-, \forestoption{edge}]
        (!u.parent anchor) -- (.child anchor)\forestoption{edge label};
    },
  }
  @+
  [\x
    [\x
      [\x
        [\x
          [\x]
          [\x]
          [\x]
        ]
        [\x
          [\x]
          [\x]
        ]
        [\x
          [\x]
        ]
      ]
      [\x]
    ]
  ]
\end{forest}

\end{document}

automatically numbering nodes with forest

cfr
  • 198,882