# How to draw graphs with tikz in LateX

Once or twice a semester I have to hand in a digital, written assignment that contains some figure with graphs. In most cases I was already using LateX so I ended up googling how to draw graphs in it. It happened again last week and I still couldn’t remember it, so another hour or so was wasted on the issue. Because I am pretty sure I will forget until text time again, I decided to save a small template as post here. Next time when I draw graphs in tikz and learn something new I might even update this post accordingly.

## Use the tikz package

```
\usepackage{tikz}
```

## Template

This is a simple template for directed and undirected graphs where nodes are drawn as circles.

```
\begin{tikzpicture}
\begin{scope}[every node/.style={circle,thick,draw}]
% \node (id) at (x,y) {x};
\end{scope}
\begin{scope}[every edge/.style={draw=black,thick}]
%\path [-] (u) edge (v);
%\path [->] (u) edge (v);
\end{scope}
\end{tikzpicture}
```

For each node you can specify its `id`

, position in cartesian coordinates `x`

and `y`

as well as a label `x`

.
The `-`

edges are undirected and `->`

are directed from node with id `u`

to `v`

.

## Bending edges

All edges drawn as above are straight. An easy way to customize the way edges are drawn is by simply bending them:

```
\path [-] (u) edge[bend right=10] (v);
```

The parameter `10`

lets you customize how much the edge is bent.