Title Page Introduction TikZ Examples Tutorial Example Source
Using Beamer and TikZ
Robb Koether & Brian Lins
Hampden-Sydney College
November 11, 2009
Title Page Introduction TikZ Examples Tutorial Example Source
Introduction
TikZ is a package that allows you to draw pictures within the
LATEXenviroment.
The radius of the innermost circle is 1. It is circumscribed by an equilateral
triangle, which is circumscribed by a circle, and so forth. The radius of the
circle as the number of figures approaches ∞ is
∞
Y π
sec ≈ 8.7
n=3
n
Figure: Created by Brian S. Marks
Title Page Introduction TikZ Examples Tutorial Example Source
Wolff’s Theorem
This is a theorem from complex analysis.
z0
Title Page Introduction TikZ Examples Tutorial Example Source
Force Diagram
Fν Ff
FG
Title Page Introduction TikZ Examples Tutorial Example Source
Supply & Demand
P
S
P2
P1 D0
D
Q1 Q2 Q
Title Page Introduction TikZ Examples Tutorial Example Source
Many More Examples
You can find many more examples of TikZ at the following website:
http://www.texample.net/tikz/examples/
Title Page Introduction TikZ Examples Tutorial Example Source
TikZ Tutorial
To use TikZ, you need to include the command
\usepackage{tikz} at the beginning of your LATEX document.
Each TikZ picture is defined within the TikZ enviroment.
\begin{tikzpicture}
...
...
\end{tikzpicture}
Title Page Introduction TikZ Examples Tutorial Example Source
TikZ Tutorial
Try the following example:
\begin{tikzpicture}
\draw[color=blue,fill=red] (0,0) circle (1);
\end{tikzpicture}
All TikZ commands should end with a semi-colon! This is very
important.
Title Page Introduction TikZ Examples Tutorial Example Source
TikZ Tutorial
Here are some other TikZ commands to try.
• A line:
\draw [options] (-5,0) -- (5,2);
• A sequence of line segments:
\draw [options] (-1,0) -- (1,0) -- (0,1) -- (0,-1);
• A rectangle:
\draw [options] (0,0) rectangle (2,2);
• An arrow: \draw [very thick, ->] (0,0) -- (2,3);
Notice that one \draw command can draw more than one object.
Title Page Introduction TikZ Examples Tutorial Example Source
TikZ Tutorial
Any time you enter a coordinate in a TikZ picture, you may add
LATEX text next to that coordinate with the node command.
\begin{tikzpicture}
\draw[semithick, color=blue] (0,0) circle (1);
\draw[semithick, <->](-2,0) -- (2,0) node[below] {$x$};
\draw[semithick, <->](0,-2) -- (0,2) node[left] {$y$};
\draw (1,1) node[above right] {$x^2+y^2= 1$};
\end{tikzpicture}
Copy this TikZ picture into LATEX, then try adding position markers
for x = −1, x = 1, y = −1, and y = 1.
Title Page Introduction TikZ Examples Tutorial Example Source
TikZ Tutorial
You can also write for-loops with TikZ, which can really save time.
For example, try the following command.
\begin{tikzpicture}
\draw[semithick,<->] (-2.5,0) -- (5.5,0);
\foreach \n in {-2,-1,0,1,2,3,4,5}
{
\fill (\n,0) circle (1.6pt) node [below=2pt] {$\n$};
}
\end{tikzpicture}
Title Page Introduction TikZ Examples Tutorial Example Source
Source Code for Examples
On the next three slides you can find the LATEX source code for the
three TikZ examples I showed at the beginning.
Title Page Introduction TikZ Examples Tutorial Example Source
Wolff’s Theorem TikZ Source
\begin{center}
\begin{tikzpicture}
\filldraw[fill=gray!0!white, draw=black]
(1.5cm,2cm) arc (30:360:2.5cm) arc(0:30:2.5cm);
\filldraw[fill=gray!20!white, draw=black]
(1.5cm,2cm) arc (30:360:1.5cm) arc(0:30:1.5cm);
\filldraw[fill=gray!70!white, draw=black]
(1.5cm,2cm) arc (30:360:1cm) arc(0:30:1cm);
\filldraw (1.5cm, 2cm) circle (0.1cm) node[right] {$z_0$};
\end{tikzpicture}
\end{center}
Title Page Introduction TikZ Examples Tutorial Example Source
Force Diagram Example Source
\begin{center}
\begin{tikzpicture}
\filldraw[fill=gray!10!white, draw=black]
(0,0) -- (5,0)-- (5,3.75) -- (0,0);
\filldraw[fill=gray!30!white, draw=black]
(2,1.5) -- (4,3) -- (3.25,4) -- (1.25,2.5) -- (2,1.5);
\draw[very thick, color=blue, ->]
(3,2) -- (3,0.8) node[below right] {$F_G$};
\draw[very thick, color=blue, ->]
(3.7,3.6) -- (4.5,4.2) node[above right] {$F_{f}$};
\draw[very thick, color=blue, ->]
(2.2,3.3) -- (1.6,4.1) node[above left] {$F_{\nu}$};
\end{tikzpicture}
\end{center}
Title Page Introduction TikZ Examples Tutorial Example Source
Supply & Demand Example Source
\begin{center}
\begin{tikzpicture}
\draw[very thick, <->] (5,0) node[below] {$Q$}
-| (0,5) node[left] {$P$};
\draw[red, thick] (0.5,0.5) parabola (4.5,4.5)
node[above] {$S$};
\draw[blue, thick] (0.5,4.5) parabola[bend at end]
(4.5,0.5) node[right] {$D$};
\draw[blue, thick] (1.5,4.5) parabola[bend at end]
(4.5,1.5) node[right] {$D’$};
\draw[dashed] (0,1.5) node[left] {$P_1$} --
(2.5,1.5) (2.5,1.5) -- (2.5,0) node[below] {$Q_1$};
\draw[dashed] (0,2.2) node[left] {$P_2$} --
(3.1,2.2) (3.1,2.2) -- (3.1,0) node[below] {$Q_2$};
\end{tikzpicture}
\end{center}