4

According to this answer: TikZ: turning edges into arrows using "child" notation one can set the style of edges for the node / child notation with the key edges from parent/.style.

However, this is not working if I use the binary tree layout

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usegdlibrary{trees}

\begin{document}

\begin{tikzpicture}[
    binary tree layout,
    edge from parent/.style={->, thick},
  ]
  \node {a}
    child{node {b} }
    child{node {c} }
    ;
\end{tikzpicture}


\end{document}

How can I style the edges with binary tree layout

3

If you are using the Lua graph drawing facilities, why not use the graph syntax?

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees}

\begin{document}

\tikz\graph [binary tree layout] { a -> {b, c}};

\end{document}

graphed tree

To style the edges, you can just add the information to the specification for the graph. For example:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees}

\begin{document}

  \tikz\graph [binary tree layout, edges={thick}] { a -> {b, c}};

\end{document}

styled edges

Note that if you prefer to specify the diagram using the standard node/child syntax, then you are not really making use of the graphs library, although you could still use the graphdrawing library (see below). In that case, it might be easier to just drop the binary tree layout and specify the shape the tree will take yourself. In this case, just drop the graphs and graph drawing stuff:

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}[
    edge from parent/.style={draw, ->, thick},
  ]
  \node {a}
    child{node {b} }
    child{node {c} }
    ;
\end{tikzpicture}
\end{document}

for very similar output:

non-graph tree

You can also use the graphdrawing library with the more standard syntax. In that case, you can apply a style to the edges using every edge/.style={}. However, specifying -> apparently has no effect:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}
  [binary tree layout, every edge/.style={draw=blue, thick, ->}]
  \node {a}
    child{node {b} }
    child{node {c} }
    ;
\end{tikzpicture}
\end{document}

no arrows despite styling the edges

Presumably there is some workaround for this, but my brief experiments did not discover it.

  • And where do I apply styles for the edges? That's the question. – MaxNoe Oct 21 '15 at 13:01
  • You just add it to the specification for the graph. See edit above. – cfr Oct 21 '15 at 13:14
  • Added a couple of further options but I'm not sure why -> is ineffective in the last tree. – cfr Oct 21 '15 at 20:35
  • Can I apply individual styling to nodes using the \graph command? – MaxNoe Oct 22 '15 at 14:05
  • And you say with using the node/child syntax I'm not using the graph drawing algorithm, but the results are vastly different if I provide this option or not. What's the reason for this? – MaxNoe Oct 22 '15 at 14:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.