LaTeX - Pgf/Tikz
Table of Contents
Introduction
Pgf/tikz is an excellent LaTeX package to plot high quality graphs. This post just summaries its basic usages.
Installation
Pgf/Tikz is a built-in package in the texlive. As long as texlive is ready, pgf/tikz is out-of-the-box.
Usage
Setting
\usepackage{tikz} ... \tikz ... \begin{tikzpicture} ... \end{tikzpicture}
Style
\tikzstyle newstylename=[option1=value1, option2=value2, ...] \tikzstyle existingstylename+=[option1=value1, option2=value2, ...]
Coordinate
(x, y)
(angle: radius)
List
% step length = 1 {a, ..., b} ... % step length = d {a, a + d, ..., b}
Arrow
- -
- ->
- <-
- <->
- ->>
Draw
Line
\draw (x1, y1) -- (x2, y2) -- (x3, y3) -- cycle
Curve
\draw (x1, y1) .. controls (x2, y2) and (x3, y3) .. (x4, y4); \draw (x1, y1) .. controls (x2, y2) .. (x3, y3);
Grid
\draw [step=s] (x1, y1) grid (x2, y2); \draw [xstep=x_s, ystep=y_s] (x1, y1) grid (x2, y2);
Arc
\draw (x1, y1) arc (start_angle: end_angle: radius);
Rectangle
\draw (x1, y1) rectangle (x2, y2); \fill [color] (x1, y1) rectangle (x2, y2); \filldraw [fill=color1, draw=color2] (x1, y1) rectangle (x2, y2); \shade [inner/top/left color=color1, outer/bottom/right color=color2] (x1, y1) rectangle (x2, y2); \shadedraw [inner/top/left color=color1, outer/bottom/right color=color2, draw=color3] (x1, y1) rectangle (x2, y2); \clip (x1, y1) rectangle (x2, y2);
Circle
\draw (x1, y1) circle (radius); \fill [color] (x1, y1) circle (radius); \filldraw [fill=color1, draw=color2] (x1, y1) circle (radius); \shade [inner/top/left color=color1, outer/bottom/right color=color2] (x1, y1) circle (radius); \shadedraw [inner/top/left color=color1, outer/bottom/right color=color2, draw=color3] (x1, y1) circle (radius); \clip (x1, y1) circle (radius);
Ellipse
\draw (x1, y1) ellipse (x_radius and y_radius); \fill [color] (x1, y1) ellipse (x_radius and y_radius); \filldraw [fill=color1, draw=color2] (x1, y1) ellipse (x_radius and y_radius); \shade [inner/top/left color=color1, outer/bottom/right color=color2] (x1, y1) ellipse (x_radius and y_radius); \shadedraw [inner/top/left color=color1, outer/bottom/right color=color2, draw=color3] (x1, y1) ellipse (x_radius and y_radius); \clip (x1, y1) ellipse (x_radius and y_radius);
Node
(x0, y0) node [anchor=north/south/east/west, shape=circle/rectangle/ellipse, draw=color1, fill=color2, label=angle:node_label_angle] (node_name) {node_label}; ... \node at (x0, y0) (node_name) {node_label};
Connecting nodes with
- Lines
\draw [arrow] (node_name_A) to (node_name_B); \draw (node_name_A) edge [arrow, color] (node_name_B);
- Curves
\draw [arrow] (node_name_A) to [bend left/right=30] (node_name_B); \draw [arrow] (node_name_A) to [in=30, out=60] (node_name_B); \draw (node_name_A) edge [arrow, color, in=30, out=60] (node_name_B); \draw (node_name_A) edge [arrow, color, bend left/right=30] (node_name_B);
Refer to nodes outside current picture
\tikzstyle{every picture}+=[remember picture] ... \tikz[overlay] \begin{tikzpicture}[overlay] ... \end{tikzpicture}
Mix tikz command with LaTeX
\tikz [baseline] ...