Graphics, Figures & TablesNodes and edges labes

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
vejn
Posts: 8
Joined: Wed Jan 30, 2013 12:59 pm

Nodes and edges labes

Post by vejn »

I need labes of edges in tikz example on page. There is only one edge with label

Code: Select all

$x$
. Could some help me to label others. I need this today.
Thanks
http://www.texample.net/tikz/examples/red-black-tree/

Code: Select all

\begin{tikzpicture}[->,>=stealth',level/.style={sibling distance = 5cm/#1,
  level distance = 1.5cm}] 
\node [arn_n] {33}
    child{ node [arn_r] {15} 
            child{ node [arn_n] {10} 
            	child{ node [arn_r] {5} edge from parent node[above left]
                         {$x$}} %for a named pointer
							child{ node [arn_x] {}}
            }
            child{ node [arn_n] {20}
							child{ node [arn_r] {18}}
							child{ node [arn_x] {}}
            }                            
    }
    child{ node [arn_r] {47}
            child{ node [arn_n] {38} 
							child{ node [arn_r] {36}}
							child{ node [arn_r] {39}}
            }
            child{ node [arn_n] {51}
							child{ node [arn_r] {49}}
							child{ node [arn_x] {}}
            }
		}
; 
\end{tikzpicture}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10328
Joined: Mon Mar 10, 2008 9:44 pm

Nodes and edges labes

Post by Stefan Kottwitz »

It's already a long time ago, but as I don't like to leave a problem unsolved, here's a way: simply add

edge from parent node[above left] {your label}

directly after a child node, such as

Code: Select all

  ...
  child{ node [arn_r] {49} edge from parent node[above left] {$y$}}
  ...
tikz-tree.png
tikz-tree.png (17.71 KiB) Viewed 6435 times
If a Infominimal working example would have been posted, I'm pretty sure somebody would have tested it to provide a solution. For example, the styles arn_r, arn_n and arn_x are unknown, I had to follow the link to example.net to get the code from there.

Stefan
LaTeX.org admin
Post Reply