Graphics, Figures & TablesAdjust angle of a node with TikZ?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Legion9o
Posts: 1
Joined: Thu May 11, 2017 11:22 am

Adjust angle of a node with TikZ?

Post by Legion9o »

Hey!
I have a problem with a tree in TiKz.
The last branches of two nodes are crossing each other.
I tried it with adding the line \tikzstyle{level 3}=[sibling angle=30]but it doesnt work.
(The other angle lines are just to see if something happend ...).

How can I adjust the angles of the branches?

Heres my tree code:

Code: Select all

\tikzset{
			treenode/.style = {align=center, inner sep=0pt, text centered,
				font=\sffamily},
			arn_n/.style = {treenode, circle, white, font=\sffamily\bfseries, draw=black,
				fill=black, text width=1.5em},% arbre rouge noir, noeud noir
			arn_r/.style = {treenode, circle, black, draw=black, 
				text width=1.5em, thin},% arbre rouge noir, noeud rouge
			arn_x/.style = {treenode, rectangle, draw=black,
				minimum width=0.5em, minimum height=0.5em}% arbre rouge noir, nil
		}
		\begin{center}
			\tikzstyle{level 1}=[sibling angle=120]
			\tikzstyle{level 2}=[sibling angle=60]
			\tikzstyle{level 3}=[sibling angle=30]
		\begin{tikzpicture}[->,>=stealth',level/.style={sibling distance = 7cm/#1,
			level distance = 1.5cm}] 
		\node [arn_r] {$n$}
		child{ node [arn_r] {$\frac{2}{3}n$} 
			child{ node [arn_r] {$\frac{4}{9}n$} 
				child{ node [arn_r] {$\frac{8}{27}n$} 
					child {node {$\vdots$}}
					 child {node {$\vdots$}}} 
				child{ node [arn_r] {$\frac{4}{27}n$}
					 child {node {$\vdots$}}
					  child {node {$\vdots$}}}
			}
			child{ node [arn_r] {$\frac{2}{9}n$}
				child{ node [arn_r] {$\frac{4}{27}n$}
					 child {node {$\vdots$}}
					  child {node {$\vdots$}}} 
				child{ node [arn_r] {$\frac{2}{27}n$}
					 child {node {$\vdots$}}
					  child {node {$\vdots$}}}
			}                            
		}
		child{ node [arn_r] {$\frac{1}{3}n$}
			child{ node [arn_r] {$\frac{2}{9}n$} 
				 child {node {$\vdots$}}
				  child {node {$\vdots$}}
			}
			child{ node [arn_r] {$\frac{1}{9}n$}
				 child {node {$\vdots$}}
				  child {node {$\vdots$}}
			}
		}
		; 
		\end{tikzpicture} 
		\end{center}
Thanks for help

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

Adjust angle of a node with TikZ?

Post by Stefan Kottwitz »

Hi,

welcome to the forum!
Legion9o wrote:How can I adjust the angles of the branches?
Instead of changing the angle, you could simply adjust the space between child nodes, such as by:

Code: Select all

\tikzset{
  level 0/.style = {sibling distance=6cm},
  level 1/.style = {sibling distance=9cm},
  level 2/.style = {sibling distance=5cm},
}
Your tree then doesn't have overlapping edges:
tree.png
tree.png (15.5 KiB) Viewed 4989 times
Stefan
LaTeX.org admin
Post Reply