# Latex Tree Diagram: Inserting Arrows

I’m having an issue formatting my LaTeX Tree Diagram. It’s in the correct order but I don’t know how to have an arrow at the end of each path to show the direction flow (test – Start) (Start – Do) (Do – Make) etc …

If people know how to have the path travel from each nodes parent only, rather than the overall 'latex' parent, that would be great!

\documentclass{tufte-handout}

% Set up the images/graphics package
\usepackage{graphicx}
\setkeys{Gin}{width=\paperwidth,totalheight=\textheight,keepaspectratio}
\graphicspath{{graphics/}}
\DeclareGraphicsExtensions{.pdf,.png}

\title{test}
\date{}  % if the \date{} command is left out, the current date will be used
% The fancyvrb package lets us customize the formatting of verbatim
% environments.  We use a slightly smaller font.
\usepackage{fancyvrb}
\fvset{fontsize=\normalsize}

% Small sections of multiple columns
\usepackage{multicol}

%colour package
\usepackage{color}

\usepackage{hyperref}

%file package
\usepackage{tikz}

%URL package
\usepackage{url}

% These commands are used to pretty-print LaTeX commands
\newcommand{\doccmd}[1]{\texttt{\textbackslash#1}}% command name -- adds backslash     automatically
\newcommand{\docopt}[1]{\ensuremath{\langle}\textrm{\textit{#1}}\ensuremath    {\rangle}}% optional command argument
\newcommand{\docarg}[1]{\textrm{\textit{#1}}}% (required) command argument
\newenvironment{docspec}{\begin{quote}\noindent}{\end{quote}}% command specification     environment
\newcommand{\docenv}[1]{\textsf{#1}}% environment name
\newcommand{\docpkg}[1]{\texttt{#1}}% package name
\newcommand{\doccls}[1]{\texttt{#1}}% document class name
\newcommand{\docclsopt}[1]{\texttt{#1}}% document class option name

\begin{document}
\begin{figure}[t]
\includegraphics[width=6cm, height=8cm]{testlogo}
\centering
\end{figure}

{\color{RoyalBlue}\maketitle}% this prints the handout title, author, and date

\tikzstyle{every node}=[draw=black,thick,anchor=west]
\tikzstyle{selected}=[draw=ProcessBlue,fill=ProcessBlue!35]

\begin{tikzpicture}[%
grow via three points={one child at (0.5,-0.7) and
two children at (0.5,-0.7) and (2.2,-1.4)},
edge from parent path={(\tikzparentnode.south) |- (\tikzchildnode.west)}]

\node [selected] {LaTeX}
child { node [selected] {1. test}}
child { node [selected] {2. start}}
child { node [selected] {3. Do}}
child { node [selected] {4. Make}}
child { node [selected] {5. test}};
\end{tikzpicture}

\end{document}


• Welcome to TeX.SX! Please complete your code in order to give a complete minimal working example (MWE), starting with \documentclass{...} and ending with \end{document}. Also, a picture of the current result and the desired output would be a great help. :) – Pier Paolo Apr 7 '15 at 18:38

Since it is a tree, I would use forest since the code is much more compact and flexible, and allows the numbering to be handled automatically.

I've used blue rather than ProcessBlue as I don't know how the latter should be defined.

I'm guessing you want something like this although it is not very clear from your question.

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\standaloneenv{forest}% delete this line if using another class
\begin{document}
\tikzset{
}
\begin{forest}
for tree={
parent anchor=south,
child anchor=west,
anchor=west,
selected,
grow=-45,
edge path={
\noexpand\path [draw, thick, -{Stealth[]}, \forestoption{edge}] (!u.parent anchor) |- (.child anchor)\forestoption{edge label};
},
},
before typesetting nodes={
for tree={
if level=0{}{
content/.wrap 2 pgfmath args={#1. #2}{level()}{content()},
},
},
}
[\LaTeX
[Test
[Start
[Do
[Make
[Test
]
]
]
]
]
]
\end{forest}

\end{document}


# EDIT

Here's a slightly enhanced version (well - you may not think so!), with a colour a little closer to that in the picture you posted.

A very subtle shading is applied to each node to give a little more depth, and the corners are rounded off.

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\standaloneenv{forest}% delete this line if using another class
\begin{document}
\colorlet{ProcessBlue}{blue!50!cyan}
\tikzset{
selected/.style={draw=ProcessBlue, thick, rounded corners=2pt, inner color=ProcessBlue!25, outer color=ProcessBlue!35, drop shadow,}
}
\begin{forest}
for tree={
parent anchor=south,
child anchor=west,
anchor=west,
selected,
grow=-45,
font=\sffamily,
edge path={
\noexpand\path [draw, thick, -{Stealth[]}, \forestoption{edge}] (!u.parent anchor) |- (.child anchor)\forestoption{edge label};
},
},
before typesetting nodes={
for tree={
if level=0{}{
content/.wrap 2 pgfmath args={#1. #2}{level()}{content()},
},
},
}
[\LaTeX
[Test
[Start
[Do
[Make
[Test
]
]
]
]
]
]
\end{forest}
\end{document}


# EDIT

In response to your comment about handling long labels, there are several possibilities. One is to use multiline nodes with explicit line breaks. This example uses align=left but you could use align=center or align=right, for example.

To create this tree, add align=left to the definition of the style selected:

\tikzset{
selected/.style={draw=ProcessBlue, thick, rounded corners=2pt, inner color=ProcessBlue!25, outer color=ProcessBlue!35, drop shadow, align=left,}
}


And then define the relevant node with line breaks where required:

            [Test a very\\loooooonnnnnnnnnggggggg\\label with line breaks
]


Alternatively, you could add text width=<some width> to the definition of selected and then the lines will be broken automatically. However, in this case, I think that manual line breaks provide the best result.

• Thanks for the help! Would you know why I'm getting this error by any chance? I think it's to do with the document class but I'm not sure. – Nyhan Apr 8 '15 at 15:35
• @Nyhan Just delete that line from the code if you are using a different class. It is only so standalone knows about forest. If you're using another class, you can just remove the line and it should be fine. – cfr Apr 8 '15 at 16:19
• @Nyhan I've also added a comment to the line in the 2 examples above so other people will know to delete it in this case. Thanks for asking - I hadn't really thought about the fact that I'd used that. – cfr Apr 8 '15 at 16:21
• This is awesome! Just out of interest, for future reference: When multiple words are entered into a node and it turns into a small sentance, the forest jets out to the right beyond the page capacity. Is there a way of break lining in a forest node? the usual \\ isn't working. Or if you know how to set the maximum width of a node, and the maximum height of the tree that would be cool too! – Nyhan Apr 10 '15 at 18:03
• @Nyhan align=left or align=center or align=right creates a multilined node. Using \\  will then break lines. You can add this in for tree={} if you want it applied to all nodes. You could also say text width=whatever for set widths. In general, anything you can use to style a TiKZ node can be passed either to a particular node or to all nodes via for tree={} as forest passes anything it doesn't recognise onto TiKZ. Does that help? – cfr Apr 10 '15 at 18:40

A MetaPost solution (using the boxes package and included in a LuaLaTeX program): as such it does not fully qualify as an answer to your problem, and I would have waited until the first tikz answer at least before introducing mine, but here I think it may serve to clarify your needs for those coming after me: is it an output like that you want?

\documentclass[border=2mm]{standalone}
\usepackage{luamplib}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
input boxes
input mpcolornames
beginfig(1);
boxit.b0(btex \LaTeX etex);
b0.se - b1.nw = (0, 2mm); % Relation between box 0 and box 1
boxjoin(a.se - b.nw = (-5mm, 2mm)); % Relation between other consecutive boxes
i := 1;
for str = "Test", "Start", "Do", "Make", "Test":
boxit.b[i](decimal i & ". " & str); i := incr(i);
endfor
% Actual drawings of boxes
for i = 0 upto 5:
fill bpath b[i] withcolor LightBlue1; drawboxed(b[i]);
endfor
% Arrows
for i = 0 upto 4:
drawarrow b[i].s -- (xpart b[i].s, ypart b[i+1].w) -- b[i+1].w;
endfor
endfig;
\end{mplibcode}
\end{document}