I want to draw a tree where each edge has a certain weight visualized through both the line width as well as a label on the edge. Using TikZ, this is pretty easy:

        clabel/.style = { fill=white, circle, inner sep=1pt,font=\scriptsize},
    \Tree [.O
        \edge [line width = 2] node [clabel] {2}; L
        \edge [line width = 4] node [clabel] {4}; R

Since the tree I want to draw is rather large, I want to factor out the edge code, i.e. I would like to have a macro like

\def\edgeweight#1{\edge [line width = #1] node [clabel] {#1}; }

Unfortunately, LaTeX complains about the \edge command when I call this macro which I assume is because it appears outside of the \Tree command. Is there a way to fix this?

1 Answer 1


Adding the following code to the preamble fixes the problem:


This solution is due to David Carlisle and is taken from here. Congrats to the guy who wrote the related questions detector, this took me straight to the right place!

You must log in to answer this question.

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