> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/in-depth-articles/26-how-to-draw-vector-graphics-using-tikz-in-latex.md).

# How to draw Vector Graphics using TikZ in LaTeX

**Author: Cody Herring (May 2013)**

### Procedural graphics in LaTeX: the basics

Traditionally, graphics are represented as bitmaps, with anything from 1 bit (black and white) to 24 bits (true color). This allows for simple display of graphics on a traditional (rectangular) computer screen. However, it can be difficult and tedious to generate bitmaps that accurately represent what should be shown on a document or on paper.

Procedural graphics help with this by allowing for a more well-defined and easily understood system such as Scalable Vector Graphics (SVG) to be used. By defining vectors, lines, and shapes rather than individual pixels, images can easily be generated for multiple sizes, aspect ratios, pixel densities, printing qualities, and more. This tutorial will provide a brief introduction into procedural graphics using Portable Graphics Format and TikZ:

* **Portable Graphics Format** (PGF) is a basic toolset, allowing for simple graphics and figures to be produced;
* **TikZ** is an extension to PGF, which allows use of multitude of pre-built figures.

Extensive documentation on TikZ and PGF can be found in the [PGF Manual](http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf).

### Using PGF and TikZ

In order to use the TikZ package, it must be imported:

```latex
\usepackage{tikz}
```

In order to draw pictures, the `tikzpicture` environment must be used:

```latex
\begin{tikzpicture}
commands go here
\end{tikzpicture}
```

### Basic drawing

TikZ allows for many different shapes and paths to be drawn. Here some basic drawing techniques will be shown. These techniques can be combined to form more complex drawings.

#### Straight paths

A straight path from one point to another can be drawn with the `\draw` command according to an X/Y (horizontal/vertical) coordinate system, like so:

```latex
\begin{tikzpicture}
\draw (5,0) -- (-5, 0);
\end{tikzpicture}
```

Multiple `\draw` calls can also be strung together. This draws a set of axes from -5 to +5 in the X direction, and -2 to +2 in the Y direction.

```latex
\begin{tikzpicture}
\draw   (5,0) -- (-5, 0)
        (0,2) -- (0,-2);
\end{tikzpicture}
```

![TikZFigure 1.png](/files/Gz5fgGxQgwVq7vyTaIZL)

Styles can be applied to these lines by adding additional parameters. Here's the same diagram, but with green, dotted, ultra thick lines rotated 15 degrees counterclockwise:

```latex
\begin{tikzpicture}
\draw[green, dotted, ultra thick, rotate=15]
        (5,0) -- (-5, 0)
        (0,2) -- (0,-2);
\end{tikzpicture}
```

![TiKZFigure 2.png](/files/DHwA37wdeXTspiydNqXb)

#### Changing the size of a diagram

Sometimes the default size of a diagram is too large or too small. Using the `scale` parameter when declaring the `tikzpicture` environment allows for different sizes while maintaining the same proportions:

```latex
\begin{tikzpicture}[scale=0.3]
\draw   (5,0) -- (-5, 0)
        (0,2) -- (0,-2);
\end{tikzpicture}
```

The following image shows the before and after effect of applying `[scale=0.3]`:

![TiKZFigure 3.png](/files/YAESM0hMJuTJM4khslfF)

#### Adding arrow tips

Arrows can be useful for graphs and diagrams, and they're simple to include in a TikZ picture. The styles demonstrated previously may be used, as well as several different arrow tips.

```latex
\begin{tikzpicture}
\draw[->](0,0) -- (5,0);
\end{tikzpicture}

\begin{tikzpicture}
\draw[<<->>](0,0) -- (5,0);
\end{tikzpicture}

\begin{tikzpicture}
\draw[<<->>, ultra thick, blue](0,0) -- (5,0);
\end{tikzpicture}

\begin{tikzpicture}
\draw[|->>, thick, red](0,0) -- (5,0);
\end{tikzpicture}
```

![TiKZFigure 4.png](/files/1XGCoT5czhnnbivJo0bC)

### Drawing curves

The simplest way to draw a curve with TikZ is by specifying the start and end point, and the desired angle leaving the start point and arriving at the end point.

```latex
\begin{tikzpicture}
\draw[ultra thick]
(0,0) to [out=75,in=135](3,4);
\end{tikzpicture}
```

![TiKZFigure 5.png](/files/uX7ecmduoL55O8orUuhG)

Much more complex diagrams can also be created using chained calls. PGF will attempt to draw the smoothest lines possible using the directions provided.

```latex
\begin{tikzpicture}
\draw[ultra thick]
(0,0)
to [out=90,in=180] (2,2)
to [out=270,in=0](0,0)
to [out=0,in=90](2,-2)
to [out=180,in=270](0,0)
to [out=270,in=0](-2,-2)
to [out=90,in=180](0,0)
to [out=180,in=270](-2,2)
to [out=0,in=90](0,0);
\end{tikzpicture}
```

![TIkZFigure 6.png](/files/ok3Yp3FtHNJrxHHfLrTM)

### Conclusion

There's no end to what can be drawn with vector graphics, and their value in allowing for scalable, easily editable diagrams and pictures is a boon to LaTeX users looking for an easy way to use graphics. This post is scratching the surface of what is possible, but should be a good introduction to the capabilities of vector graphics and the TikZ/PGF environment.

Additional resources:

* [Minimal introduction to TikZ](http://cremeronline.com/LaTeX/minimaltikz.pdf);
* [CTAN documentation on TikZ & PGF](http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf);
* [Overleaf's learn Wiki page](/latex/figures-and-tables/05-tikz-package.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/in-depth-articles/26-how-to-draw-vector-graphics-using-tikz-in-latex.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
