LaTeX forum ⇒ TeXShopAdding text to edge in a recursion tree Topic is solved

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

Adding text to edge in a recursion tree

Postby jay_singh » Fri Oct 09, 2020 7:59 am

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 272 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 272 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.

Bartman
Posts: 128
Joined: Fri Jan 03, 2020 2:39 pm

Postby Bartman » Fri Oct 09, 2020 8:53 am

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

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. child{node{abc,1,2}
  2. child{node{abc,2,2}}
  3. child{node{acb,2,2}}
  4. edge from parent node[above left] {i=0}
  5. }

You can also draw trees with the forest package.


Return to “TeXShop”

Who is online

Users browsing this forum: No registered users and 2 guests