TikZ Package: Drawing Graphics in LaTeX
Date Published

TikZ: Graphics in LaTeX
TikZ lets you create publication-quality diagrams directly in LaTeX.
Getting Started
\usepackage{tikz}
Basic drawing environment:
\begin{tikzpicture} ...drawing commands... \end{tikzpicture}
Basic Shapes
Lines
\draw (0,0) -- (2,0); — horizontal line
\draw (0,0) -- (2,2); — diagonal line
Rectangles
\draw (0,0) rectangle (2,1);
Circles
\draw (0,0) circle (1cm);
Ellipses
\draw (0,0) ellipse (2cm and 1cm);
Coordinates
Cartesian
(x, y) — x units right, y units up
Relative
++(1,1) — relative to current position
Named
\coordinate (A) at (0,0); \draw (A) -- (B);
Nodes
Nodes are points with optional labels:
Basic Node
\node at (0,0) {Text};
Positioned Node
\node[above] at (0,0) {Label above};
\node[below right] at (0,0) {Below right};
Styled Node
\node[circle, draw, fill=blue!20] {A};
Paths
Draw (stroked path)
\draw (0,0) -- (1,1) -- (2,0);
Fill (filled path)
\fill[blue] (0,0) rectangle (1,1);
Filldraw (both)
\filldraw[fill=yellow, draw=black] (0,0) circle (1);
Styling
Line Styles
\draw[dashed] (0,0) -- (2,0);
\draw[dotted] (0,0) -- (2,0);
\draw[thick] (0,0) -- (2,0);
\draw[line width=2pt] (0,0) -- (2,0);
Colors
\draw[red] (0,0) -- (1,1);
\draw[blue!50] (0,0) -- (1,1); — 50% blue
Arrows
\draw[->] (0,0) -- (2,0); — arrow at end
\draw[<->] (0,0) -- (2,0); — arrows both ends
\draw[->, thick] (0,0) -- (2,0);
Curved Paths
Bezier Curves
\draw (0,0) .. controls (1,1) .. (2,0);
Smooth Curves Through Points
\draw plot[smooth] coordinates {(0,0) (1,1) (2,0)};
Arcs
\draw (0,0) arc (0:90:1cm); — start:end:radius
Grids
\draw[step=1cm, gray, thin] (0,0) grid (4,4);
Transformations
Shift
\draw[shift={(1,1)}] (0,0) circle (0.5);
Scale
\draw[scale=2] (0,0) rectangle (1,1);
Rotate
\draw[rotate=45] (0,0) rectangle (1,1);
TikZ Libraries
Load additional features:
\usetikzlibrary{shapes, arrows, positioning}
Common libraries: - shapes — more shapes - arrows — arrow styles - positioning — relative positioning - calc — coordinate calculations - patterns — fill patterns
Flowcharts
With shapes and arrows:
\node[rectangle, draw] (start) {Start}; \node[rectangle, draw, below=of start] (process) {Process}; \draw[->] (start) -- (process);
Mathematical Plots
\draw[domain=0:2*pi, samples=100] plot (\x, {sin(\x r)});
Common Patterns
Labeled Diagram
\node[circle, draw] (A) at (0,0) {A}; \node[circle, draw] (B) at (2,0) {B}; \draw[->] (A) -- node[above] {edge} (B);
Coordinate System
\draw[->] (-0.5,0) -- (3,0) node[right] {$x$}; \draw[->] (0,-0.5) -- (0,3) node[above] {$y$};
Create TikZ Diagrams with Octree
Octree helps with TikZ:
- Preview diagrams in real-time - AI suggests correct syntax - Visual coordinate feedback - Export vector graphics
Try it at https://useoctree.com