Tutorial Tikz
Tutorial Tikz
Tutorial Tikz
What is Tikz?
Tikz Commands
Exercises
Outlook: Potential of Tikz
Fancy Examples
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 2/37
What is TikZ?
Source: http://www.texample.net
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 3/37
Why using TikZ?
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 4/37
Scaling Effects
sin(x) sin(x )
x x
sin(x) sin(x )
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 5/37
Math Environment
ṅ = u − v δψ (3)
ė = u δψ + v (4)
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 6/37
Loops
Layer 0 Layer 1 Layer 2 Layer 3
Output Bus
Pattern3 word FF word FF word FF word FF
matchline
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 7/37
Setting up the Environment in LATEX
\ documentclass { standalone }
\ usepackage { tikz }
\ us etikzlib rary { ... }
\ begin { document }
\ begin { tikzpicture }
% TikZ c o m m a n d s go here
\ end { tikzpicture }
\ end { document }
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 8/37
The \draw Command
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 9/37
Coordinates
Cartesian Coordinates (x,y)
\ draw [ blue ] (0 ,0) -- (2 ,1);
Define Coordinates
\ coordinate (A) at (0 ,0);
\ coordinate (B) at (1 ,1);
\ coordinate (C) at (2 ,0);
\ draw [ blue ] (A) -- ( B ) -- ( C );
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 10/37
The \node Command
Node positioning
Rectangle
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 11/37
Style Definitions
example
\ tikzset { my dot /. style ={ blue , fill = green , thick }}
\ draw [ my dot ] (0 ,0) circle (0.2);
\ draw [ my dot ] (0.1 ,0.6) circle (0.2);
\ draw [ my dot , fill = red ] (0.8 ,0.2) circle (0.2);
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 12/37
Exercise 1: UML Activity Diagram
wake up
yes
tired?
no
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 13/37
Exercise 1: UML Activity Diagram
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 14/37
Exercise 1: UML Activity Diagram
wake up
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 15/37
Exercise 1: UML Activity Diagram
wake up
tired?
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 16/37
Exercise 1: UML Activity Diagram
wake up
tired?
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 17/37
Exercise 1: UML Activity Diagram
wake up
tired?
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 18/37
Exercise 1: UML Activity Diagram
wake up
tired?
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 19/37
Exercise 1: UML Activity Diagram
\ draw [ - >]( decision 1) -- node [ left , very near start ]{ no } ( action 2);
\ draw [ - >]( decision 1) -| node [ above , very near start ]{ yes } ( action 3)
wake up
yes
tired?
no
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 20/37
Exercise 1: UML Activity Diagram -
Solution I
% \ u s e t i k z l i b r a r y { shapes }
\ begin { tikzpicture }
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 21/37
Exercise 1: UML Activity Diagram -
Solution II
\ end { tikzpicture }
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 22/37
Exercise 2: p-p collision
p e+
p
n
p ν
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 23/37
Exercise 2: p-p collision - Solution I
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 24/37
Exercise 2: p-p collision - Solution II
( collision 1) {};
\ node [ positron , right = 8 cm of proton 1] ( positron 1) {};
\ node [ font =\ Huge ] at ( positron 1) {\ textbf { e $^+$}};
\ node [ neutrino , right = 8 cm of proton 2] ( neutrino 1) {};
\ node [ font =\ Huge ] at ( neutrino 1) {\ textbf {$\ nu $}};
\ node [ proton , below right = 1.25 cm and 10 cm of proton 1]
( proton 3) {};
\ node [ font =\ Huge ] at ( proton 3) {\ textbf { p }};
\ node [ neutron , below of = proton 3] ( neutron 1) {};
\ node [ font =\ Huge ] at ( neutron 1) {\ textbf { n }};
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 25/37
Feynman Diagram
W
q q
q q
g
q q
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 26/37
Feynman Diagram - Code I
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 27/37
Feynman Diagram - Code II
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 28/37
Plotting Data
f (x )
5 f (x ) = 1 + 13 x 2
0 x
0 1 2 3 4 5 6
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 29/37
Plotting data - Code
\ begin { tikzpicture }[ domain =0.2:6]
\ draw [ - > , >= stealth ’] ( -0.2 ,0) -- (7 ,0) node [ right ] {$ x $};
\ draw [ - > , >= stealth ’] (0 , -0.2) -- (0 ,6) node [ above ] {$ f ( x )$};
\ draw plot [ only marks , mark =x , mark options ={ kit - blue 100 , thick }]
file { working _ material / measurement . dat };
\ draw [ color = kit - green 100] plot [ smooth ] (\ x , {1+ pow ((1/3)*\ x , 2)})
node [ right , xshift =6 mm ] {$ f ( x ) = 1+\ frac {1}{3} x ^{2}$};
\ end { tikzpicture }
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 30/37
Mind Map
algorithms
data
structures
pro-
gramming
languages
software
engineer-
ing
technical applied
databases
WWW
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 31/37
Mind Map - Code I
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 32/37
Mind Map - Code II
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 33/37
Fancy Examples - Polarizing Microscope
z
y
Polarized light
oid ng0
Crystal section
lar np0
Po Polarized and
~
E dephased light
Polaroid
x
Source: http://www.texample.net
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 34/37
Fancy Examples - Dipolar magnetic field
B~θ
Sm
~r
B
Nm
B~θ
~r
B
Source: http://www.texample.net
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 35/37
More information
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 36/37
Thank you for your attention
Christian Amstutz, Tanja Harbaum, Ewa Holt – TikZ Tutorial July 21, 2014 37/37