a brief introduction into tikz - tu dresden · i what is tikz? i how to draw figures? i how to...

47
I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch Sibylle M¨ ohle A brief introduction into TikZ 1 A brief introduction into TikZ Sibylle M ¨ ohle International Center for Computational Logic Technische Universit¨ at Dresden Germany

Upload: habao

Post on 04-Aug-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

I What is TikZ?

I How to draw figures?

I How to place text inside the figures?

These slides are based on slides of Tobias Pietzsch

Sibylle MohleA brief introduction into TikZ 1

A brief introduction into TikZ

Sibylle MohleInternational Center for Computational LogicTechnische Universitat DresdenGermany

Page 2: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

PGF and TikZ

I PGF (portable graphics format)

. package for creating graphics “inline”

. TEX and LATEX input

. PDF, PostScript, and SVG output

. three layers: System, Basic, and Frontend

I TikZ(TikZ is not a drawing program)

. is a frontend layer for PGF (portable graphics format)

. high-level user interface

. this introduction refers to version 2.10

. for features and bug-fixes: http://www.texample.net/tikz/builds/

I Written by Till Tantau (author of Beamer package) and Mark Wibrow

Sibylle MohleA brief introduction into TikZ 2

Page 3: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Setup your environment

I Use a LATEX document

I Use the TikZ package and required TikZ libraries

\usepackage{tikz}

\usetikzlibrary{...}

I Draw TikZ figure in the document.

\begin{tikzpicture}

\draw (0,0) circle (0.5);

\draw (-0.5,-0.5) -- (0.5,0.5);

\end{tikzpicture}

\tikz \draw (0,0) circle (0.5);

Sibylle MohleA brief introduction into TikZ 3

Page 4: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Setup your environment

I Use a LATEX document

I Use the TikZ package and required TikZ libraries

\usepackage{tikz}

\usetikzlibrary{...}

I Draw TikZ figure in the document.

\begin{tikzpicture}

\draw (0,0) circle (0.5);

\draw (-0.5,-0.5) -- (0.5,0.5);

\end{tikzpicture}

\tikz \draw (0,0) circle (0.5);

Sibylle MohleA brief introduction into TikZ 4

Page 5: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Setup your environment

I Use a LATEX document

I Use the TikZ package and required TikZ libraries

\usepackage{tikz}

\usetikzlibrary{...}

I Draw TikZ figure in the document.

\begin{tikzpicture}

\draw (0,0) circle (0.5);

\draw (-0.5,-0.5) -- (0.5,0.5);

\end{tikzpicture}

\tikz \draw (0,0) circle (0.5);

Sibylle MohleA brief introduction into TikZ 5

Page 6: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Drawing Basics

I A path is a series of straight and curved line segments

I Syntax:

\path (path-operation | graphic-option)* ;

I There are two major operations: draw and node

I \draw is an abbreviation for \path [draw]

. Next, drawing figures by using \draw is presented

. By using \node text is added afterwards

Sibylle MohleA brief introduction into TikZ 6

Page 7: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Drawing with paths

I A step by step example for \draw:

\begin{tikzpicture}

\path [draw] (0,0) circle (0.5)

(-0.5,-0.5) -- (0.5,0.5) ;

\end{tikzpicture}

Sibylle MohleA brief introduction into TikZ 7

Page 8: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Drawing with paths

I A step by step example for \draw:

\begin{tikzpicture}

\path [draw] (0,0) circle (0.5)

(-0.5,-0.5) -- (0.5,0.5) ;

\end{tikzpicture}

I Move-To Operation: move to coordinate (0,0)

I without drawing anything

Sibylle MohleA brief introduction into TikZ 8

Page 9: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Drawing with paths

I A step by step example for \draw:

\begin{tikzpicture}

\path [draw] (0,0) circle (0.5)

(-0.5,-0.5) -- (0.5,0.5) ;

\end{tikzpicture}

I Circle Operation: draw circle with radius (0.5)

I current point remains (0,0)

Sibylle MohleA brief introduction into TikZ 9

Page 10: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Drawing with paths

I A step by step example for \draw:

\begin{tikzpicture}

\path [draw] (0,0) circle (0.5)

(-0.5,-0.5) -- (0.5,0.5) ;

\end{tikzpicture}

I Move-To Operation: move to coordinate (-0.5,-0.5)

I without drawing anything

Sibylle MohleA brief introduction into TikZ 10

Page 11: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Drawing with paths

I A step by step example for \draw:

\begin{tikzpicture}

\path [draw] (0,0) circle (0.5)

(-0.5,-0.5) -- (0.5,0.5) ;

\end{tikzpicture}

I Line-To Operation: line to coordinate (0.5,0.5)

Sibylle MohleA brief introduction into TikZ 11

Page 12: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Drawing with paths

I A step by step example for \draw:

\begin{tikzpicture}

\path [draw] (0,0) circle (0.5)

(-0.5,-0.5) -- (0.5,0.5) ;

\end{tikzpicture}

I Path ends.

Sibylle MohleA brief introduction into TikZ 12

Page 13: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Graphic Options

I Add color and line styles to the picture:

\begin{tikzpicture}

\draw (0,0) circle (0.5);

\draw (-0.5,-0.5) -- (0.5,0.5);

\end{tikzpicture}

Sibylle MohleA brief introduction into TikZ 13

Page 14: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Graphic Options

I Add color and line styles to the picture:

\begin{tikzpicture}

\draw [color=blue] (0,0) circle (0.5);

\draw (-0.5,-0.5) -- (0.5,0.5);

\end{tikzpicture}

I Add color to the line.

Sibylle MohleA brief introduction into TikZ 14

Page 15: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Graphic Options

I Add color and line styles to the picture:

\begin{tikzpicture}

\draw [color=blue, fill=blue!20!white] (0,0) circle (0.5);

\draw (-0.5,-0.5) -- (0.5,0.5);

\end{tikzpicture}

I Fill the circle with color.

Sibylle MohleA brief introduction into TikZ 15

Page 16: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Graphic Options

I Add color and line styles to the picture:

\begin{tikzpicture}

\draw [color=blue, fill=blue!20!white,fill opacity=0.6]

(0,0) circle (0.5);

\draw (-0.5,-0.5) -- (0.5,0.5);

\end{tikzpicture}

I Make circle transparent.

Sibylle MohleA brief introduction into TikZ 16

Page 17: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Graphic Options

I Add color and line styles to the picture:

\begin{tikzpicture}

\draw [color=blue, fill=blue!20!white,fill opacity=0.6]

(0,0) circle (0.5);

\draw [thick] (-0.5,-0.5) -- (0.5,0.5);

\end{tikzpicture}

I Draw a thick line.

Sibylle MohleA brief introduction into TikZ 17

Page 18: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Graphic Options

I Add color and line styles to the picture:

\begin{tikzpicture}

\draw [color=blue, fill=blue!20!white,fill opacity=0.6]

(0,0) circle (0.5);

\draw [thick, dashed] (-0.5,-0.5) -- (0.5,0.5);

\end{tikzpicture}

I Draw a dashed line.

Sibylle MohleA brief introduction into TikZ 18

Page 19: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Graphic Options

I Add color and line styles to the picture:

\begin{tikzpicture}

\draw [color=blue, fill=blue!20!white,fill opacity=0.6]

(0,0) circle (0.5);

\draw [thick, dashed, ->] (-0.5,-0.5) -- (0.5,0.5);

\end{tikzpicture}

I Draw an arrow.

Sibylle MohleA brief introduction into TikZ 19

Page 20: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Graphic Options

I Add color and line styles to the picture:

\begin{tikzpicture}

\draw [color=blue, fill=blue!20!white,fill opacity=0.6]

(0,0) circle (0.5);

\draw [thick, dashed, ->, rotate=30]

(-0.5,-0.5) -- (0.5,0.5);

\end{tikzpicture}

I Rotate the arrow.

Sibylle MohleA brief introduction into TikZ 20

Page 21: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Scoping and Grouping Graphic Options

I Grouping multiple graphic options:

\begin{tikzpicture}

\draw [orange, very thick] (0,0) circle (0.5);

\draw [orange, very thick](-0.5,-0.5) -- (0.5,0.5);

\draw [orange, very thick](0.5,-0.5) -- (-0.5,0.5);

\end{tikzpicture}

Sibylle MohleA brief introduction into TikZ 21

Page 22: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Scoping and Grouping Graphic Options

I Grouping multiple graphic options:

\begin{tikzpicture} [orange, very thick]

\draw (0,0) circle (0.5);

\draw(-0.5,-0.5) -- (0.5,0.5);

\draw(0.5,-0.5) -- (-0.5,0.5);

\end{tikzpicture}

I Define a set of options for the whole figure.

Sibylle MohleA brief introduction into TikZ 22

Page 23: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Scoping and Grouping Graphic Options

I Grouping multiple graphic options:

\begin{tikzpicture}

\draw (0,0) circle (0.5);

\begin{scope} [orange, very thick]

\draw(-0.5,-0.5) -- (0.5,0.5);

\draw(0.5,-0.5) -- (-0.5,0.5);

\end{scope}

\end{tikzpicture}

I Set a scope.

Sibylle MohleA brief introduction into TikZ 23

Page 24: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Scoping and Grouping Graphic Options

I Grouping multiple graphic options:

\begin{tikzpicture}

[marked/.style = {orange, very thick}]

\draw (0,0) circle (0.5);

\draw [marked] (-0.5,-0.5) -- (0.5,0.5);

\draw [marked] (0.5,-0.5) -- (-0.5,0.5);

\end{tikzpicture}

I Define a style.

Sibylle MohleA brief introduction into TikZ 24

Page 25: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Scoping and Grouping Graphic Options

I Grouping multiple graphic options:

\tikzset{marked/.style = {orange, very thick}}

\begin{tikzpicture}

\draw (0,0) circle (0.5);

\draw [marked] (-0.5,-0.5) -- (0.5,0.5);

\draw [marked] (0.5,-0.5) -- (-0.5,0.5);

\end{tikzpicture}

I Draw a global style.

Sibylle MohleA brief introduction into TikZ 25

Page 26: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Scoping and Grouping Graphic Options

I Grouping multiple graphic options:

\tikzset{marked/.style = {orange, very thick}}

\begin{tikzpicture}

\draw (0,0) circle (0.5);

\draw [marked,blue] (-0.5,-0.5) -- (0.5,0.5);

\draw [marked,dashed] (0.5,-0.5) -- (-0.5,0.5);

\end{tikzpicture}

I Properties of styles can be overwritten.

Sibylle MohleA brief introduction into TikZ 26

Page 27: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Coordinates

I There exists multiple coordinate systems

. Polar coordinates are not introduced here

I Absolute coordinates\tikz \draw [thick,red] (0,0) -- (2mm, 0) -- (2mm, 5pt);

I Relative coordinates\tikz \draw [thick,red] (0,0) -- +(2mm, 0) -- +(0, 5pt);

I Relative coordinates\tikz \draw [thick,red] (0,0) -- ++(2mm, 0) -- +(0, 5pt);

I Named points\tikz \draw [thick,red] (10mm,1mm) coordinate (c1) circle (5pt)

(0,0) -- (c1);

Sibylle MohleA brief introduction into TikZ 27

Page 28: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Nodes

I A node is a simple shape with some text on it.

hello \tikz \path node [shape=circle, draw, color=red] {hello};

I Constructed using the path-operation node.

I \path node can be abbreviated as \node.

I shape= and color= can be omitted if there is no confusion.

Sibylle MohleA brief introduction into TikZ 28

Page 29: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Nodes

I A node is a simple shape with some text on it.

hello \tikz \node [circle, draw, red] {hello};

I Constructed using the path-operation node.

I \path node can be abbreviated as \node.

I shape= and color= can be omitted if there is no confusion.

Sibylle MohleA brief introduction into TikZ 29

Page 30: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Node Syntax

\path ... node [options] (name) at (coordinate) {contents} ...;

I options may contain node shape, color, sizes, labels, . . .

I A node may get a name for later reference.

I A node may be placed using at (coordinate).(Otherwise it is placed at the current path coordinate.)

I Nodes contents can be (almost) arbitrary LATEX.

TikZ is quite liberal with respect to the order of the arguments.

hello \tikz \node [circle] at (0,0) [draw] (hello) [red] {hello};

Sibylle MohleA brief introduction into TikZ 30

Page 31: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Node Syntax

\path ... node [options] (name) at (coordinate) {contents} ...;

I options may contain node shape, color, sizes, labels, . . .

I A node may get a name for later reference.

I A node may be placed using at (coordinate).(Otherwise it is placed at the current path coordinate.)

I Nodes contents can be (almost) arbitrary LATEX.

TikZ is quite liberal with respect to the order of the arguments.

hello \tikz \node [circle] at (0,0) [draw] (hello) [red] {hello};

Sibylle MohleA brief introduction into TikZ 31

Page 32: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Node Syntax

\path ... node [options] (name) at (coordinate) {contents} ...;

I options may contain node shape, color, sizes, labels, . . .

I A node may get a name for later reference.

I A node may be placed using at (coordinate).(Otherwise it is placed at the current path coordinate.)

I Nodes contents can be (almost) arbitrary LATEX.

TikZ is quite liberal with respect to the order of the arguments.

hello \tikz \node [circle] at (0,0) [draw] (hello) [red] {hello};

Sibylle MohleA brief introduction into TikZ 32

Page 33: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Placing Nodes

p1 p1 pn

\begin{tikzpicture}

\node [packet] (p1) at (0,0.5) {$p_1$};

\node [packet] (p1) at (1,0.5) {$p_1$};

\node [packet] (p1) at (4,0.5) {$p_1$};;

\end{tikzpicture}

I Can be placed at absolute positions.

Sibylle MohleA brief introduction into TikZ 33

Page 34: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Placing Nodes

p1 p2 pn

\begin{tikzpicture}

\node [packet] (p1) at (0,0.5) {$p_1$};

\node [packet,right=0.25 of p1] (p2) {$p_2$};

\node [packet,right=2 of p2] (pn) {$p_n$};

\end{tikzpicture}

I Relative placement allows to say things like:

. “Node (p2) should be right of (p1)” (wherever (p1) happens to be).

. Requires the positioning TikZ library:\usetikzlibrary{positioning}

. available: right=of, below=of, above left=of, . . .

Sibylle MohleA brief introduction into TikZ 34

Page 35: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Connecting Nodes

I We can simply draw paths between node anchors.

a

b

\usetikzlibrary{arrows}

\begin{tikzpicture}[>=latex’]

\node [circle, draw] (a) {a};

\node [circle, draw] (b) [above right=of a] {b};

\draw [->] (a.east) -- (b.west);

\end{tikzpicture}

I Each node has anchors, e.g. east, west, center, . . .

I If anchor specifications are left out TikZ tries to be smart about the anchor itshould choose.

I Another path operation -|

I Again, TikZ is clever about the correct anchors

Sibylle MohleA brief introduction into TikZ 35

Page 36: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Connecting Nodes

I We can simply draw paths between node anchors.

a

b

\usetikzlibrary{arrows}

\begin{tikzpicture}[>=latex’]

\node [circle, draw] (a) {a};

\node [circle, draw] (b) [above right=of a] {b};

\draw [->] (a) -- (b);

\end{tikzpicture}

I Each node has anchors, e.g. east, west, center, . . .

I If anchor specifications are left out TikZ tries to be smart about the anchor itshould choose.

I Another path operation -|

I Again, TikZ is clever about the correct anchors

Sibylle MohleA brief introduction into TikZ 36

Page 37: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Connecting Nodes

I We can simply draw paths between node anchors.

a

b

\usetikzlibrary{arrows}

\begin{tikzpicture}[>=latex’]

\node [circle, draw] (a) {a};

\node [circle, draw] (b) [above right=of a] {b};

\draw [->] (a) -| (b);

\end{tikzpicture}

I Each node has anchors, e.g. east, west, center, . . .

I If anchor specifications are left out TikZ tries to be smart about the anchor itshould choose.

I Another path operation -|

I Again, TikZ is clever about the correct anchors

Sibylle MohleA brief introduction into TikZ 37

Page 38: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Connecting Nodes

I A very powerful path operation is to.

a

b \begin{tikzpicture}[>=latex’]

\node [circle, draw] (a) {a};

\node [circle, draw] (b) [above right=of a] {b};

\draw [->] (a) to (b);

\end{tikzpicture}

Sibylle MohleA brief introduction into TikZ 38

Page 39: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Connecting Nodes

I A very powerful path operation is to.

a

b \begin{tikzpicture}[>=latex’]

\node [circle, draw] (a) {a};

\node [circle, draw] (b) [above right=of a] {b};

\draw [->] (a) to [bend left=45] (b);

\end{tikzpicture}

Sibylle MohleA brief introduction into TikZ 39

Page 40: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Connecting Nodes

I A very powerful path operation is to.

a

b \begin{tikzpicture}[>=latex’]

\node [circle, draw] (a) {a};

\node [circle, draw] (b) [above right=of a] {b};

\draw [->] (a) to [out=0, in=180] (b);

\end{tikzpicture}

Sibylle MohleA brief introduction into TikZ 40

Page 41: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Labeling Connections

I Connections can be labeled by inserting text nodes in the path.

a

b \begin{tikzpicture}

\node [circle, draw] (a) {a};

\node [circle, draw] (b) [above right=of a] {b};

\draw [->] (a) to [bend left=45] (b);

\end{tikzpicture}

I The auto option places the label such that it is next to the path and doesn’toverlap anything.

I swap places the label on the other side of the path.

I Instead of auto, also left, above, right and below can be used

Sibylle MohleA brief introduction into TikZ 41

Page 42: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Labeling Connections

I Connections can be labeled by inserting text nodes in the path.

a

bf\begin{tikzpicture}

\node [circle, draw] (a) {a};

\node [circle, draw] (b) [above right=of a] {b};

\draw [->] (a) to [bend left=45] node [auto] {$f$} (b);

\end{tikzpicture}

I The auto option places the label such that it is next to the path and doesn’toverlap anything.

I swap places the label on the other side of the path.

I Instead of auto, also left, above, right and below can be used

Sibylle MohleA brief introduction into TikZ 42

Page 43: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Labeling Connections

I Connections can be labeled by inserting text nodes in the path.

a

bf\begin{tikzpicture}

\node [circle, draw] (a) {a};

\node [circle, draw] (b) [above right=of a] {b};

\draw [->] (a) to [bend left=45] node [auto] {$f$} (b);

\end{tikzpicture}

I The auto option places the label such that it is next to the path and doesn’toverlap anything.

I swap places the label on the other side of the path.

I Instead of auto, also left, above, right and below can be used

Sibylle MohleA brief introduction into TikZ 43

Page 44: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Labeling Connections

I Connections can be labeled by inserting text nodes in the path.

a

b

f

\begin{tikzpicture}

\node [circle, draw] (a) {a};

\node [circle, draw] (b) [above right=of a] {b};

\draw [->] (a) to [bend left=45] node [auto,swap] {$f$}(b);

\end{tikzpicture}

I The auto option places the label such that it is next to the path and doesn’toverlap anything.

I swap places the label on the other side of the path.

I Instead of auto, also left, above, right and below can be used

Sibylle MohleA brief introduction into TikZ 44

Page 45: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Labeling Connections

I Connections can be labeled by inserting text nodes in the path.

a

bf

\begin{tikzpicture}

\node [circle, draw] (a) {a};

\node [circle, draw] (b) [above right=of a] {b};

\draw [->] (a) to [bend left=45] node [left] {$f$}(b);

\end{tikzpicture}

I The auto option places the label such that it is next to the path and doesn’toverlap anything.

I swap places the label on the other side of the path.

I Instead of auto, also left, above, right and below can be used

Sibylle MohleA brief introduction into TikZ 45

Page 46: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

For Loop

I For drawing multiple objects a for loop can be used

I Loops can be nested

\begin{tikzpicture}

\foreach \y in {1,2,3} {

\draw [blue, ultra thick] (0,\y ) circle [radius=0.3];

}

\end{tikzpicture}

Sibylle MohleA brief introduction into TikZ 46

Page 47: A brief introduction into TikZ - TU Dresden · I What is TikZ? I How to draw figures? I How to place text inside the figures? These slides are based on slides of Tobias Pietzsch

Good PracticeI Place nodes relative to each other

I Do not use to many colors and styles

I Do not overload figures.

I Further information:

. Gnuplot has a TikZ terminal

. Inkscape can export to TikZ

. Dia is another GUI that can export TikZ

. see http://www.texample.net/tikz/resources/

. documentationhttp://www.texample.net/media/pgf/builds/pgfmanualCVS2012-11-04.pdf

(v2.10-CVS)ftp://ftp.tu-chemnitz.de/pub/tex/graphics/pgf/base/doc/pgfmanual.pdf

(v3.01a)

Sibylle MohleA brief introduction into TikZ 47