Skip to content

Instantly share code, notes, and snippets.

@xaedes
Last active May 31, 2018 20:35
Show Gist options
  • Save xaedes/3402aba3ea82728c4ad9142dde5a528c to your computer and use it in GitHub Desktop.
Save xaedes/3402aba3ea82728c4ad9142dde5a528c to your computer and use it in GitHub Desktop.
UML2 Activity Diagram with Tikz in Latex
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[T1]{fontenc}
%\usepackage{fontspec}
% http://www.texample.net/tikz/examples/diagram-chains/
\usetikzlibrary{%
arrows,%
calc,
shapes,
arrows,
shapes.misc,% wg. rounded rectangle
shapes.arrows,%
chains,%
matrix,%
positioning,% wg. " of "
scopes,%
decorations.pathmorphing,% /pgf/decoration/random steps | erste Graphik
shadows%
}
\usepackage{amsmath}
\usepackage{relsize}
\begin{document}
\tikzset{% UML2 Activity Diagram Styles
process/.style = {fill=black!5,draw, thick, rounded corners=0.8em, minimum height = 3em,
minimum width = 3em, align=center, inner sep=1em,node distance=4em},
object/.style = {fill=black!5,draw, thick, rectangle, minimum height = 3em,
minimum width = 3em, align=center, inner sep=1em,node distance=4em},
pin/.style = {fill=black!5,draw, thick, rectangle, minimum height = 0.6em,
minimum width = 0.6em, node distance=-1pt, inner sep=0,font=\relsize{-3.5}},
start/.style = {fill=black,draw,circle,node distance=4em},
group/.style = {color=black,thin,rounded corners=0.8em, rectangle},
groupCaption/.style = {above=0.2cm,right=0.2cm,fill=white},
input/.style = {coordinate,node distance=2em},
output/.style = {coordinate,node distance=2em},
between/.style args={#1 and #2}{ % http://tex.stackexchange.com/a/138828/15602
at = ($(#1)!0.5!(#2)$)
}
}
%\makeGroup{Title}{Top}{Left}{Width}{Height}
\newcommand{\makeGroup}[5]{
\draw [group](#2-0.5,#3+1.5-#5)rectangle(#2+#4+0.5,#3+1.5);
\node at (#2,#3+1.5) [groupCaption] {\textsc{#1}};
}
\begin{tikzpicture}[auto, thick, node distance=2cm, >=triangle 45]
% Boxing and labelling
\makeGroup{cook spaghetti}{0}{0}{11.5}{5.0}
\draw
node at (0,0) [object](SpaghettiRaw){spaghetti\\{[raw]}}
node [process, right=of SpaghettiRaw](AddSpaghetti){add spaghetti\\To water}
node [pin,right=of AddSpaghetti](PinSpaghettiInWater){2}
node [pin,left=of AddSpaghetti](PinSpaghettiRaw){}
node [pin,below=of AddSpaghetti](PinBoilingWater){}
node [process, right=of AddSpaghetti](CookSpaghetti){cook spaghetti\\for 10min}
node [pin,left=of CookSpaghetti](PinSpaghettiInWater2){}
node [pin,right=of CookSpaghetti](PinCookedSpaghetti){}
node [pin,below=of CookSpaghetti](PinUsedWater){}
node [pin,below=of CookSpaghetti, right=0.1em of PinUsedWater](PinExample2){}
node [process, below=of AddSpaghetti](BoilWater){boil water}
node [start, left=of BoilWater](Start){}
node [object, right=of BoilWater, below=6 em of PinUsedWater](Water){<<water>>}
node [object, right=of CookSpaghetti](SpaghettiAldente){spaghetti\\{[al dente]}}
node [input,left=of SpaghettiRaw](Input){}
node [output, right=of SpaghettiAldente](Output){}
;
% Commands \draw with options like [->] must be written individually
\draw[->](PinSpaghettiInWater) -- (PinSpaghettiInWater2);
\draw[->](Start) -- (BoilWater);
\draw[->](BoilWater) -- (PinBoilingWater);
\draw[->](SpaghettiRaw) -- (PinSpaghettiRaw);
\draw[->](PinCookedSpaghetti) -- (SpaghettiAldente);
\draw[->](Input) -- (SpaghettiRaw);
\draw[->](SpaghettiAldente) -- (Output);
\draw[->](Water) |- (BoilWater);
\draw[->](PinUsedWater) -- (Water) node (A) [pos=0.4, anchor=west] {used water};
\end{tikzpicture}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment