tikz tutorial - massachusetts institute of...

29
TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick Horelik (MIT) TikZ Tutorial February 14, 2014 1 / 20

Upload: dongoc

Post on 06-Feb-2018

232 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

TikZ Tutorial

Nick Horelik

MIT

February 14, 2014

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 1 / 20

Page 2: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

What Is TikZ?

• PGF: Portble Graphics Format (or “pretty, good, functional”)• Tikz: Tikz ist kein Zeichenprogramm• Allows creation of vector graphic schemes, charts, diagrams, ...• Placed inline in the middle of text• In floats

potent perimeter sites

Non−metallic molecule

extra electron

single metal atom

Figure: A tikzpicture

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 2 / 20

Page 3: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

The Good and the Bad

• Pros• Programatically draw with exact precision• Consistent typography• Very fast for simple graphics

• Cons• Steep learning curve• No WYSIWYG• Changes require recompile

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 3 / 20

Page 4: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

TONS of help online

• Manual and primer: www.ctan.org/pkg/pgf

• Search the document! e.g. search /tikz/every node

• Huge example repository: www.texample.net/tikz/

• Vibrant community for specific help: tex.stackexchange.com/

Google is your best friend!(try searching for “tikz arrow head size”)

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 4 / 20

Page 5: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Drawing a Path

\draw[help lines, thick] (0,0) grid (4,4);

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 5 / 20

Page 6: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Drawing a Path

\draw[help lines, thick] (0,0) grid (4,4);

\draw (0,0) -- (1,2);

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 5 / 20

Page 7: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Drawing a Path

\draw[help lines, thick] (0,0) grid (4,4);

\draw[->] (0,0) -- (1,2);

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 5 / 20

Page 8: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Drawing a Path

\draw[help lines, thick] (0,0) grid (4,4);

\draw[->,>=diamond] (0,0) -- (1,2);

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 5 / 20

Page 9: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Drawing a Path

\draw[help lines, thick] (0,0) grid (4,4);

\draw[->,>=diamond,thick] (0,0) -- (1,2);

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 5 / 20

Page 10: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Drawing a Path

\draw[help lines, thick] (0,0) grid (4,4);

\draw[->,>=diamond,thick,red] (0,0) -- (1,2);

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 5 / 20

Page 11: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Drawing a Path

\draw[help lines, thick] (0,0) grid (4,4);

\draw[->,>=diamond,thick,red] (0,0) -- (1,2) -| (3,4);

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 5 / 20

Page 12: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Drawing a Path

\draw[help lines, thick] (0,0) grid (4,4);

\draw[->,>=diamond,thick,red] (0,0) -- (1,2) |- (3,4);

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 5 / 20

Page 13: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Drawing a Path

\draw[help lines, thick] (0,0) grid (4,4);

\draw[->,>=diamond,thick,red] (0,0) -- (1,2) -| (3,4) -- (1,1);

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 5 / 20

Page 14: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Tikz Core Concepts: Points

• Points: (1cm,2pt)

• Relative points:

(5,5) (1,0) (1,1) (0,1)

(5,5) (6,0) (6,6) (6,7)

+ ++ +

• Named locations: node.south

• 3D points: (1,1,2)

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 6 / 20

Page 15: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Tikz Core Concepts: Idea of Paths

• Series of straight or curved lines

• \path(2em,0) -- (0,0) -- (0,2em) -- cycle

• Can act on paths: draw, fill, shade, clip

• Attributes can be applied mid-path

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 7 / 20

Page 16: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Tikz Core Concepts: Key-Value Parameters, Nodes

• Attributes are set everywhere with key=value

• Nodes are inserted at the current position of a path, or at a specifiedlocation

text

• Nodes can have options too

text

• Nodes can be named to reference their coordinates

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 8 / 20

Page 17: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Tikz Core Concepts: Trees

• Nodes can be arranged in trees automatically

root

left right

child child

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 9 / 20

Page 18: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Tikz Core Concepts: Scopes

• Attributes can be applied to all objects in a scope

• Check out /tikz/every path, and /tikz/every node

i’m a node

i’m a node too

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 10 / 20

Page 19: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Tikz Core Concepts: Transformations

• Coordinates can be transformed

• Nodes can be moved tooi’m a node

i’m a node too

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 11 / 20

Page 20: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Decision Tree

I’m cooking

Should I add cheeseto my meal?

You should add cheese

Add cheese

But I don’t like cheese

No

Yes

Everyone loves cheese

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 12 / 20

Page 21: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Styles, Libraries, Colors

I’m cooking

Should I add cheeseto my meal?

You should add cheese

Add cheese

But I don’t like cheese

No

Yes

Everyone loves cheese

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 13 / 20

Page 22: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Hyperlinks

thingsare goodand bad

pathsare cool

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 14 / 20

Page 23: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Text Overlays

• You can use tikz over the text with overlay

• Node names are available to future tikzpictures withremember picture

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 15 / 20

Page 24: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Stacked Figures in Beamer

• Stacking pictures in Beamer is easy with overlays

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 16 / 20

Page 25: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Stacked Figures in Beamer

• Stacking pictures in Beamer is easy with overlays

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 16 / 20

Page 26: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Plotting Functions

x

f (x)

f (x) = x

f (x) = sin x

f (x) = 120e

x

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 17 / 20

Page 27: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Plotting Data

6 8 10 12 14 160

5000

10000

15000

20000

25000

Education

Inco

me

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 18 / 20

Page 28: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: Membrane and Ions

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 19 / 20

Page 29: TikZ Tutorial - Massachusetts Institute of Technologyweb.mit.edu/custer/Desktop/custer/MacData/afs/sipb/project/latex/... · TikZ Tutorial Nick Horelik MIT February 14, 2014 Nick

Example: 3D Random Walk

Nick Horelik (MIT) TikZ Tutorial February 14, 2014 20 / 20