TikZ

Aus SDQ-Wiki
Wechseln zu: Navigation, Suche

TikZ (TikZ ist kein Zeichenprogramm) ist ein LaTeX-Paket, mit dem man sehr einfach qualitativ hochwertige Graphiken erstellen kann. Es wurde von Till Tantau, entwickelt, der auch das Paket beamer entwickelt hat. TikZ funktioniert (im Gegensatz zu ähnlichen Paketen wie pstricks) unabhängig vom Ausgabeformat des LaTeX-Dokuments (DVI/PS/PDF) und eignet sich besonders gut für Präsentationen mit Beamer.

Ressourcen

  • TeXample – eine Seite mit nützlichen Beispielen
  • PGF and TikZ – Homepage des Projekts. Sehr lesenswert ist das PGF Manual, das im Paket enthalten ist.

PCM-Symbole in TikZ

Die folgenden Zeichnungen benötigen die Datei beamercolorthemekit.sty aus der SDQ-Beamer-Vorlage. Außerdem müssen folgende Pakete importiert werden:

\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{fit}
\usetikzlibrary{petri}
\usetikzlibrary{shapes}

Component

\begin{tikzpicture}
	\node (text) at (0,0) {\small complete component};
	\node[fill=white,draw=black,rectangle, minimum width=1.2em, minimum height=1.2em]	
		(componentsymbol) at	([yshift=1.5em,xshift=-1em]text.east) {};
	\filldraw[fill=white,draw=black]	
		([xshift=-1em,yshift=.1em]componentsymbol)	rectangle	+(.7em,.3em)
		([xshift=-1em,yshift=.-.1em]componentsymbol)	rectangle	+(.7em,-.3em);
	\node[draw=black, inner sep = .5em] 	(component1) [fit=(text) (componentsymbol)] {};
	\draw (component1.west) -- ([xshift=-1em]component1.west);
	\node[circle, minimum size=1ex, draw] (lolli1) at ([xshift=-1em-1ex]component1.west) {};

	\draw (component1.east) -- ([xshift=1em]component1.east);
	\draw ([xshift=1em+1.4ex,yshift=1.4ex]component1.east) arc (90:270:1.4ex);
\end{tikzpicture}
Tikz component.png

Internal Action

\begin{tikzpicture}
	\node[shade, ball color=kit-blue100, circle, minimum size=.7ex] (intactionsign) {};
	\draw[thick] (intactionsign.north) -- ([yshift=.5ex]intactionsign.north);
	\draw[thick] (intactionsign.south) -- ([yshift=-.5ex]intactionsign.south);
\end{tikzpicture}
Tikz intaction.png

External Call Action

\begin{tikzpicture}
	\node[shade, ball color=kit-blue100, circle, minimum size=.7ex] (extactionsign) {};
	\draw[thick,<-] (extactionsign.north) -- ([yshift=1ex]extactionsign.north);
	\draw[thick,->] (extactionsign.south) -- ([yshift=-.8ex]extactionsign.south);
	\draw[ultra thick,-&gt;,color=red!70!black] (extactionsign.east) -- ([xshift=1ex]extactionsign.east);
\end{tikzpicture}
Tikz extaction.png

Loop Action

\begin{tikzpicture}
	\clip (-1ex,-1ex) rectangle (1.8ex,2.1ex);
	\node[shade, ball color=kit-blue100, circle, minimum size=.7ex] (loopball) {} 
	edge [->, in=30, out=90, looseness=1, distance=2ex, thick] node {} (loopball);
\end{tikzpicture}
Tikz loopaction.png

Branch

\begin{tikzpicture}
	\node[scale=.4, diamond, shade, ball color=kit-blue100] (branchsign) {\color{white}\Large\textbf?};
	\draw[thick] (branchsign.north) -- ([yshift=.8ex]branchsign.north);
	\draw[thick] (branchsign.south west) -- ([xshift=-.7ex,yshift=-.7ex]branchsign.south west);
	\draw[thick] (branchsign.south east) -- ([xshift=.7ex, yshift=-.7ex]branchsign.south east);
\end{tikzpicture}
Tikz branch.png

Fork

\begin{tikzpicture}[very thick,black!75]
	\draw (0,0) -- (0,.4em) -- (1em,.4em) -- (1em,0em);
	\draw (.33em,.4em) -- (.33em,0em);
	\draw (.66em,.4em) -- (.66em,0em);
	\draw (.5em,1em) -- (.5em,.4em);
	\draw (.2em,.75em) -- (.5em,.45em) -- (.8em,.75em);
\end{tikzpicture
Tikz forkaction.png

Probabilistic Branch

\begin{tikzpicture}
	[point/.style={circle,fill=black,minimum size=.4ex,inner sep=0pt}]
\begin{scope}[every node/.append style={yslant=-0.5},yslant=-0.5]
	\shade[right color=white, left color=kit-blue30, draw=black, 
		rounded corners=.1ex] (0,0) rectangle +(1em,1em);
	\node [point] 	at (.25em,.25em) {};
	\node [point] 	at (.25em,.75em) {};
	\node [point] 	at (.5em,.5em) {};
	\node [point] 	at (.75em,.25em) {};
	\node [point] 	at (.75em,.75em) {};
\end{scope}

\begin{scope}[every node/.append style={yslant=0.5},yslant=0.5]
	\shade[left color=white, right color=kit-blue30, draw=black, 
		rounded corners=.1ex] (1em,-1em) rectangle +(1em,1em);
	\node [point] 	at (1.25em,-.25em) {};
	\node [point] 	at (1.25em,-.75em) {};
	\node [point] 	at (1.75em,-.25em) {};
	\node [point] 	at (1.75em,-.75em) {};
\end{scope}


\begin{scope}[every node/.append style={
    yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
  ]
  \shade[bottom color=white, top color=kit-blue30, draw=black, 
		rounded corners=.1ex] (2em,1em) rectangle +(-1em,-1em);
	\node [point] 	at (1.25em,.25em) {};
	\node [point] 	at (1.25em,.75em) {};
	\node [point] 	at (1.5em,.25em) {};
	\node [point] 	at (1.5em,.75em) {};
	\node [point] 	at (1.75em,.25em) {};
	\node [point] 	at (1.75em,.75em) {};
\end{scope}

	\draw[thick, color=black] (.5em,-.25em) -- +(-.7ex,-.7ex);
	\draw[thick, color=black] (1.5em,-.25em) -- +(.7ex,-.7ex);

\end{tikzpicture
Tikz probbranch.png

Set Variable Action

\begin{tikzpicture}
	\node[rectangle,draw=gray,ultra thick,dashed] (setvar) {\$x};
\end{tikzpicture}
Tikz setvar.png

Collection Iterator Action

\begin{tikzpicture}[decoration={
	markings, mark=at position .5 with {\arrow[red, line width=.2ex]{>}}}]
\node[matrix,draw=black!75, row sep=.3ex, inner sep=.3ex]	(text) {
	\draw[red,thick] (0,0) -- (.7ex,0);\\
	\draw[red,thick] (0,0) -- (.7ex,0);\\
	\draw[red,thick] (0,0) -- (.7ex,0);\\ };
\draw [thick,black!75,postaction=decorate] 
	(text.south) .. controls (0,-1.5ex) and (1.4ex,-1.5ex) .. 
	(1.4ex,0) .. controls (1.4ex,1.5ex) and (0,1.5ex) .. (text.north);
\end{tikzpicture}
Tikz collit.png

Acquire Action

\begin{tikzpicture}[every token/.style={color=kit-blue100,minimum size=.2ex}]
	\node[place, minimum size=1em,shade,
		bottom color=kit-blue30,top color=white,shading angle=30] {}
		[children are tokens, token distance=.4ex]
		child {node [token] {}}
		child {node [token] {}}
		child {node (inlier) [token] {}}
		child {node [token] {}}
		child {node [token] {}}
		child {node [token] {}}
		child {node [token] {}};
	\node[token] (outlier) at (.6em,.6em) {};
	\draw[->, red, very thick] (inlier) -- (outlier);
\end{tikzpicture}
Tikz acqaction.png

Release Action

\begin{tikzpicture}[every token/.style={color=kit-blue100,minimum size=.2ex}]
	\node[place, minimum size=1em,shade,
		bottom color=kit-blue30,top color=white,shading angle=30] {}
		[children are tokens, token distance=.4ex]
		child {node [token] {}}
		child {node [token] {}}
		child {node (inlier) [token] {}}
		child {node [token] {}}
		child {node [token] {}}
		child {node [token] {}}
		child {node [token] {}};
	\node[token] (outlier) at (.6em,.6em) {};
	\draw[<-, red, very thick] (inlier) -- (outlier);
\end{tikzpicture}
Tikz relaction.png

Beispiel-SEFF

Beispiele für ganze SEFFs finden sich im internen SVN (ggf. Betreuer fragen, zum Beispiel unter https://svnserver.informatik.kit.edu/i43/svn/paper/2010/Burger_WCOP2010/paper

Makros

Mit einfachen Makros werden die Bilder übersichtlicher:


\newcommand{\tikzComponent}[4]{
	\node (#4_text) at (#1,#2) {\small #3};
	\node[fill=white,draw=black,rectangle, minimum width=1.2em, minimum height=1.2em]	
		(#4_componentsymbol) at	([yshift=1.5em,xshift=-1em]#4_text.east) {};
	\filldraw[fill=white,draw=black]	
		([xshift=-1em,yshift=.1em]#4_componentsymbol)	rectangle	+(.7em,.3em)
		([xshift=-1em,yshift=.-.1em]#4_componentsymbol)	rectangle	+(.7em,-.3em);
	\node[draw=black, inner sep = .5em] 	(#4_component) [fit=(#4_text) (#4_componentsymbol)] {};
	\draw (#4_component.west) -- ([xshift=-1em]#4_component.west);
	\node[circle, minimum size=1ex, draw] (#4_lolli) at ([xshift=-1em-1ex]#4_component.west) {};
	\draw (#4_component.east) -- ([xshift=1em]#4_component.east);
	\draw ([xshift=1em+1.4ex,yshift=1.4ex]#4_component.east) arc (90:270:1.4ex);
}

\newcommand{\tikzComponentP}[4]{
	\node (#4_text) at (#1,#2) {\small #3};
	\node[fill=white,draw=black,rectangle, minimum width=1.2em, minimum height=1.2em]	
		(#4_componentsymbol) at	([yshift=1.5em,xshift=-1em]#4_text.east) {};
	\filldraw[fill=white,draw=black]	
		([xshift=-1em,yshift=.1em]#4_componentsymbol)	rectangle	+(.7em,.3em)
		([xshift=-1em,yshift=.-.1em]#4_componentsymbol)	rectangle	+(.7em,-.3em);
	\node[draw=black, inner sep = .5em] 	(#4_component) [fit=(#4_text) (#4_componentsymbol)] {};
	\draw (#4_component.west) -- ([xshift=-1em]#4_component.west);
	\node[circle, minimum size=1ex, draw] (#4_lolli) at ([xshift=-1em-1ex]#4_component.west) {};
}

\newcommand{\tikzComponentR}[4]{
	\node (#4_text) at (#1,#2) {\small #3};
	\node[fill=white,draw=black,rectangle, minimum width=1.2em, minimum height=1.2em]	
		(#4_componentsymbol) at	([yshift=1.5em,xshift=-1em]#4_text.east) {};
	\filldraw[fill=white,draw=black]	
		([xshift=-1em,yshift=.1em]#4_componentsymbol)	rectangle	+(.7em,.3em)
		([xshift=-1em,yshift=.-.1em]#4_componentsymbol)	rectangle	+(.7em,-.3em);
	\node[draw=black, inner sep = .5em] 	(#4_component) [fit=(#4_text) (#4_componentsymbol)] {};
	\draw (#4_component.east) -- ([xshift=1em]#4_component.east);
	\draw ([xshift=1em+1.4ex,yshift=1.4ex]#4_component.east) arc (90:270:1.4ex);
}

\newcommand{\tikzDeployment}[2]{
	\node (#1_deploytext) at ([yshift=4em]#1_component) {\small #2};
	\node[draw=black, inner sep = 3em] (#1_deploy) [fit=(#1_component)] {};
	\draw (#1_deploy.north west) -- +(1em,1em); 
	\draw (#1_deploy.north east) -- +(1em,1em);
	\draw (#1_deploy.south east) -- +(1em,1em);
	\draw ([xshift=1em,yshift=1em]#1_deploy.north west) -- ([xshift=1em,yshift=1em]#1_deploy.north east) -- ([xshift=1em,yshift=1em]#1_deploy.south east);
}

\newcommand{\tikzConnection}[2]{
	\draw [dashed, ->] ([xshift=1em]#1_component.east)--(#2_lolli.west);
}

Nun kann man sehr einfach komplexere Bilder erstellen.

\begin{tikzpicture}
	\tiny

	\tikzComponentR{0}{0}{client application}{client}
	\tikzDeployment{client}{client}

	\tikzComponentP{4}{0}{service}{service}
	\tikzDeployment{service}{server}

	\tikzConnection{client}{service}	
\end{tikzpicture}
Tikz complex.png

Einfügen als externes Bild

Definition:

\newif\iffinal % introduce a switch for draft vs. final document
%\finaltrue % use this to compile the final document

% [more preamble that in my case also uses \iffinal for other stuff]

\pgfrealjobname{proposal} % <-- NOTE: this needs to be the real document's basename
                        %     (else you'll only get an empty output file)

\iffinal
  \newcommand{\inputTikZ}[1]{%
    \input{#1.tikz}%
  }
\else
  \newcommand{\inputTikZ}[1]{%
    \beginpgfgraphicnamed{#1-external}%
    \input{#1.tikz}%
    \endpgfgraphicnamed%
  }
\fi

Bild einfügen das in figs/picture.tikz gespeichert ist:

\begin{figure}[t]
\centering
% like \input{...}, but adds caching via PGF's externalization feature:
\inputTikZ{figs/picture}
\caption{\label{fig:isoosi-model}ISO/OSI stack with the network model and the PCM  scope.}
\end{figure}