# TexLive TikZ Graphics **TikZ** is a powerful drawing package for creating diagrams, flowcharts, plots, and graphics programmatically. Load with `\usepackage{tikz}`. Drawings are created inside `tikzpicture` environments using commands that specify paths, shapes, and styling. Basic drawing uses coordinates and paths. A path connects points with straight lines or curves. `\draw` renders lines; `\fill` fills shapes; `\node` places text. ```latex \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw (0,0) -- (2,0) -- (2,1) -- (0,1) -- cycle; \node at (1, 0.5) {Rectangle}; \end{tikzpicture} \end{document} ``` This draws a rectangle from (0,0) to (2,1) with "Rectangle" centered inside. `cycle` closes the path back to the start. Coordinates are in centimeters by default. **Circles and ellipses:** ```latex \begin{tikzpicture} \draw (1,1) circle (0.5); % circle at (1,1) with radius 0.5cm \draw (3,1) ellipse (1cm and 0.5cm); % ellipse (horizontal and vertical radii) \fill[blue] (5,1) circle (0.3); % filled circle \end{tikzpicture} ``` **Styling** uses options in square brackets: color, line width, fill, etc. ```latex \begin{tikzpicture} \draw[thick, red] (0,0) -- (2,0); \draw[line width=2pt, blue] (0,1) -- (2,1); \fill[green] (1,2) circle (0.3); \draw[dashed] (0,3) -- (2,3); \end{tikzpicture} ``` **Arrows and nodes:** ```latex \begin{tikzpicture}[node distance=2cm] \node (A) at (0,0) {A}; \node (B) at (2,0) {B}; \draw[->] (A) -- (B); % arrow from A to B \draw[<->] (A) to[bend left=30] (B); % curved arrow \end{tikzpicture} ``` The `->` makes arrowheads; `<->` makes double-headed arrows. `to[bend left=30]` curves the line; adjust the angle to curve more or less. **Grids and axes** are useful for plots: ```latex \begin{tikzpicture} \draw[gray, thin] (0,0) grid (4,3); \draw[->] (-0.5,0) -- (4,0) node[right] {$x$}; \draw[->] (0,-0.5) -- (0,3) node[above] {$y$}; \draw[blue, thick] (0,0) -- (2,2) -- (4,1); \end{tikzpicture} ``` The grid provides reference lines. Nodes on arrow ends label axes. **Plot functions:** ```latex \begin{tikzpicture} \draw[gray, thin] (0,0) grid (4,2); \draw[blue, thick, domain=0:4] plot (\x, {sin(\x * 180 / pi)}); \end{tikzpicture} ``` `plot` draws a function. `domain=0:4` sets the x-range. Use `\x` for the variable; wrap expressions in `{...}`. Trig functions use degrees, so multiply radians by `180/pi`. **Flowcharts** combine rectangles and arrows: ```latex \begin{tikzpicture}[node distance=2cm] \node[rectangle, draw] (start) {Start}; \node[rectangle, draw, below of=start] (process) {Process}; \node[diamond, draw, below of=process] (decision) {Decision}; \draw[->] (start) -- (process); \draw[->] (process) -- (decision); \end{tikzpicture} ``` Node shapes: `rectangle`, `circle`, `ellipse`, `diamond`. The `[below of=...]` option positions relative to another node. **Standalone documents** compile TikZ drawings independently. Use `\documentclass{standalone}` instead of `article`: ```latex \documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw (0,0) circle (1); \end{tikzpicture} \end{document} ``` This produces a PDF sized exactly to fit the drawing—no extra margins. Useful for creating graphics to include in other documents with `\includegraphics`. TikZ is complex but powerful. Start with simple paths and shapes, then explore advanced features (graphs, matrix layouts, 3D projections) as needed. Read the [TikZ manual](http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf) for comprehensive documentation.