TeXShopAdding text to edge in a recursion tree

Information and discussion about TeXShop, an integrated LaTeX environment for Mac OS X
Post Reply
jay_singh
Posts: 9
Joined: Tue Jul 14, 2020 6:27 pm

Adding text to edge in a recursion tree

Post by jay_singh »

Hello colleagues,
I have following tree drawn in Texshop;(please see image attached)
Screen Shot 2020-10-08 at 10.50.19 PM.png
Screen Shot 2020-10-08 at 10.50.19 PM.png (38.84 KiB) Viewed 55335 times
Next I want to add a text in the edge between abc,0,2 and abc,1,2. Here is the code I am using for this purpose;

\usepackage{tikz}
\usetikzlibrary{shapes, arrows.meta, automata, positioning, matrix, backgrounds, decorations.pathmorphing}
\usepackage{color}
\definecolor{airforceblue}{rgb}{0.36,0.54,0.66}
%\usegdlibrary{trees}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{center}

\begin{tikzpicture}[ level 1/.style={sibling distance=40mm}, level 2/.style={sibling distance=15mm}]

\node[red]{abc,0,2}
[level distance=15mm]
child{node{abc,1,2} edge from parent node[left,draw=none] {i=0}
child{node{abc,2,2}}
child{node{acb,2,2}}
}
child{node{bac,1,2}
child{node{bac,2,2}}
child{node{bca,2,2}}
}
child{node{cba,1,2}
child{node{cba,2,2}}
child{node{cab,2,2}}
}

;
\end{tikzpicture}
\end{center}


But this is not placing the text at correct place, please see screenshot.
Screen Shot 2020-10-08 at 10.56.03 PM.png
Screen Shot 2020-10-08 at 10.56.03 PM.png (42.66 KiB) Viewed 55335 times
Can I kindly get some help on how to place the text at correct place? Kindly let me know what I am doing wrong in the code.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Bartman
Posts: 366
Joined: Fri Jan 03, 2020 2:39 pm

Adding text to edge in a recursion tree

Post by Bartman »

Please read the manual to find out where to add the code to label the edge.

Code: Select all

child{node{abc,1,2} 
    child{node{abc,2,2}}
    child{node{acb,2,2}}
    edge from parent node[above left] {i=0}
}
You can also draw trees with the forest package.
Post Reply