lecture 9 - tikz and pgf - open computing facilitylatex/files/tikz_lecture.pdf · what is...

30
What is TikZ? Before We Get Started Example to Get Us Started More Advance Example, K Lecture 9 - TikZ and pgf L A T E X for Math and Science Christian Blanco and Brandon Eltiste Spring 2011 Lecture 7 L A T E X for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Upload: others

Post on 07-Aug-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Lecture 9 - TikZ and pgf

LATEX for Math and ScienceChristian Blanco and Brandon Eltiste

Spring 2011 Lecture 7

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 2: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Outline

1 What is TikZ?

2 Before We Get Started

3 Example to Get Us Started

4 TikZ libraries

5 Background example

6 More Advance Example, Koch Snowflake

7 Resources

8 Homework

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 3: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

What is TikZ?

A package for creating pictures (Show examples).Create anything from rectangles, circles to Kochsnowflakes, 3D graphs and animations.

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 4: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

What is TikZ?

A package for creating pictures (Show examples).Create anything from rectangles, circles to Kochsnowflakes, 3D graphs and animations.

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 5: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Before We Get Started

You need to add \usepackage{tikz} into yourpreamble. Other commands to put in preamble will bediscussed later.When creating a picture use the tikzpictureenvironment. E.g.:\begin{tikzpicture}

...\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 6: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Before We Get Started

You need to add \usepackage{tikz} into yourpreamble. Other commands to put in preamble will bediscussed later.When creating a picture use the tikzpictureenvironment. E.g.:\begin{tikzpicture}

...\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 7: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Getting Started with Basic Examples

\begin{tikzpicture}\draw[line width=2pt,color=red]

(1,0) -- (0,0) -- (0,1);\end{tikzpicture}

\begin{tikzpicture}\draw[line width=2pt,color=red]

(1,0) -- (0,0) -- (0,1) -- cycle;\end{tikzpicture}

Note: Don’t forget the semicolons.LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 8: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Getting Started with Basic Examples

\begin{tikzpicture}\draw[line width=2pt,color=red]

(1,0) -- (0,0) -- (0,1);\end{tikzpicture}

\begin{tikzpicture}\draw[line width=2pt,color=red]

(1,0) -- (0,0) -- (0,1) -- cycle;\end{tikzpicture}

Note: Don’t forget the semicolons.LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 9: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Getting Started with Basic Examples

\begin{tikzpicture}\draw[line width=2pt,color=red]

(1,0) -- (0,0) -- (0,1);\end{tikzpicture}

\begin{tikzpicture}\draw[line width=2pt,color=red]

(1,0) -- (0,0) -- (0,1) -- cycle;\end{tikzpicture}

Note: Don’t forget the semicolons.LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 10: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Getting Started with Basic Examples

\begin{tikzpicture}\draw[line width=2pt,color=red]

(1,0) -- (0,0) -- (0,1);\end{tikzpicture}

\begin{tikzpicture}\draw[line width=2pt,color=red]

(1,0) -- (0,0) -- (0,1) -- cycle;\end{tikzpicture}

Note: Don’t forget the semicolons.LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 11: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Getting Started with Basic Examples

\begin{tikzpicture}\draw[line width=2pt,color=red]

(1,0) -- (0,0) -- (0,1);\end{tikzpicture}

\begin{tikzpicture}\draw[line width=2pt,color=red]

(1,0) -- (0,0) -- (0,1) -- cycle;\end{tikzpicture}

Note: Don’t forget the semicolons.LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 12: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Getting Started with Basic Examples

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) {[rounded corners]-- (0,1)} -- (1,0);

\end{tikzpicture}

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) {[rounded corners]-- (0,1) -- (1,0)} -- cycle;

\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 13: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Getting Started with Basic Examples

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) {[rounded corners]-- (0,1)} -- (1,0);

\end{tikzpicture}

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) {[rounded corners]-- (0,1) -- (1,0)} -- cycle;

\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 14: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Getting Started with Basic Examples

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) {[rounded corners]-- (0,1)} -- (1,0);

\end{tikzpicture}

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) {[rounded corners]-- (0,1) -- (1,0)} -- cycle;

\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 15: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Getting Started with Basic Examples

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) {[rounded corners]-- (0,1)} -- (1,0);

\end{tikzpicture}

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) {[rounded corners]-- (0,1) -- (1,0)} -- cycle;

\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 16: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

More Getting Started with Basic Examples

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) rectangle (2,1);\end{tikzpicture}

\begin{tikzpicture}\draw[line width=2pt,color=gray]

(0,0) circle[radius=1];\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 17: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

More Getting Started with Basic Examples

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) rectangle (2,1);\end{tikzpicture}

\begin{tikzpicture}\draw[line width=2pt,color=gray]

(0,0) circle[radius=1];\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 18: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

More Getting Started with Basic Examples

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) rectangle (2,1);\end{tikzpicture}

\begin{tikzpicture}\draw[line width=2pt,color=gray]

(0,0) circle[radius=1];\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 19: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

More Getting Started with Basic Examples

\begin{tikzpicture}\fill[line width=1pt,color=blue]

(0,0) rectangle (2,1);\end{tikzpicture}

\begin{tikzpicture}\draw[line width=2pt,color=gray]

(0,0) circle[radius=1];\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 20: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

TikZ Libraries

To provide simpler methods to create complex structureslibraries for TikZ has \usetikzlibaryDifferent examples are: decorations.fractals,arrows, backgrounds, intersections andshapes.geometric.And now for some examples using these...

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 21: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

First you must add \usetikzlibrary{backgrounds}to your preamble

\begin{tikzpicture}[background rectangle/.style={fill=blue!20,

draw=blue!50,line width=3pt},show background rectangle]

\draw[line width=2pt,color=gray](2,2) circle[radius=1];

\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 22: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

First you must add \usetikzlibrary{backgrounds}to your preamble

\begin{tikzpicture}[background rectangle/.style={fill=blue!20,

draw=blue!50,line width=3pt},show background rectangle]

\draw[line width=2pt,color=gray](2,2) circle[radius=1];

\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 23: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

First you must add \usetikzlibrary{backgrounds}to your preamble

\begin{tikzpicture}[background rectangle/.style={fill=blue!20,

draw=blue!50,line width=3pt},show background rectangle]

\draw[line width=2pt,color=gray](2,2) circle[radius=1];

\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 24: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Koch Snowflake

First you must add\usetikzlibrary{decorations.fractals} to yourpreamble\begin{tikzpicture}[decoration=Koch

snowflake,draw=blue,fill=blue!20,thick]\filldraw decorate{ decorate{ (0,0) --

++(60:1) -- ++(-60:1) -- cycle}};\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 25: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Koch Snowflake

First you must add\usetikzlibrary{decorations.fractals} to yourpreamble\begin{tikzpicture}[decoration=Koch

snowflake,draw=blue,fill=blue!20,thick]\filldraw decorate{ decorate{ (0,0) --

++(60:1) -- ++(-60:1) -- cycle}};\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 26: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Koch Snowflake

First you must add\usetikzlibrary{decorations.fractals} to yourpreamble\begin{tikzpicture}[decoration=Koch

snowflake,draw=blue,fill=blue!20,thick]\filldraw decorate{ decorate{ (0,0) --

++(60:1) -- ++(-60:1) -- cycle}};\end{tikzpicture}

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 27: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 28: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Don’t forget

At the end of each statement put a semi-colon.

Don’t forget to put the correct TikZ library in your preamble.

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 29: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Resources

PGF Manual

TikZ Examples

Extra TikZ slides

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf

Page 30: Lecture 9 - TikZ and pgf - Open Computing Facilitylatex/files/tikz_lecture.pdf · What is TikZ?Before We Get StartedExample to Get Us Started TikZ librariesBackground exampleMore

What is TikZ? Before We Get Started Example to Get Us Started TikZ libraries Background example More Advance Example, Koch Snowflake Resources Homework

Homework

Homework

LATEX for Math and Science Christian Blanco and Brandon Eltiste Lecture 9 - TikZ and pgf