Last active
August 29, 2015 14:01
-
-
Save pafmaf/c3e2f7f0f81e8f194e65 to your computer and use it in GitHub Desktop.
trees in tex with tikz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass[german,11pt]{article} | |
\usepackage{tikz} | |
\usepackage{pgfplots} | |
\usepgfplotslibrary{dateplot} | |
\usetikzlibrary{arrows} | |
\usetikzlibrary{positioning} | |
\usetikzlibrary{external} | |
\usetikzlibrary{graphs,quotes,graphdrawing,arrows.meta,backgrounds} | |
\usegdlibrary{layered,trees} | |
\usetikzlibrary{arrows.spaced,arrows} | |
\usetikzlibrary{positioning} | |
\begin{document} | |
\tikzset{ | |
graphs/graph/.style={ | |
nodes={circle, draw, minimum size=7mm}, | |
edges={-{Stealth[round,sep]},semithick}, | |
} | |
} | |
\def\mywidth{5mm} | |
\begin{tikzpicture}[ | |
semithick, | |
> = spaced stealth', | |
box/.style={ | |
draw, thick, black, rectangle, | |
minimum height = 5mm, | |
minimum width = \mywidth, | |
}, | |
node distance=0pt, | |
] | |
\begin{scope}[yscale=1.4] | |
\node (root) at (-1,0) {\textsc{root}}; | |
\foreach \x/\y/\a/\b/\c [count=\d] in {% | |
1/0/1//,% | |
0/-1/2/0/,% | |
2.5/-1/2//1,% | |
1/-2/3/0/1, | |
1/-3/4/5/6% | |
} | |
{ | |
\coordinate (x) at (\x,\y); | |
\node [box] at ( x) (box \d a) {\a}; | |
\node [box] at ([xshift=\mywidth] x) (box \d b) {\b}; | |
\node [box] at ([xshift=2*\mywidth]x) (box \d c) {\c}; | |
} | |
\draw (root) edge[->] (box 1a); | |
\draw [out=-90,in=90] | |
(box 1b.center) edge [->] (box 2c) | |
(box 1c.center) edge [->] (box 3b) | |
(box 2c.center) edge [->] (box 4b) | |
(box 3b.center) edge [->] (box 4c) | |
; | |
\end{scope} | |
\foreach \start in {box 1b,box 1c,box 2c,box 3b} | |
\fill (\start.center) circle[radius=2pt]; | |
\end{tikzpicture} | |
\begin{tikzpicture} | |
\graph [graph,tree layout] { | |
/ -> { | |
/ -> { | |
/, | |
/ -> { | |
/, / | |
}, | |
/, | |
, | |
/ -> / | |
}, | |
/ -> { | |
/, / | |
} | |
} | |
}; | |
\end{tikzpicture} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment