Graphs? No, not pie graphs. Not even graphs of functions. THESE graphs.

Yesterday I tried making LaTeX notes for one of my maths courses. Not so much because I needed digital notes (to be honest it would have been much faster on paper), but because I wanted to get some practice at typing up documents in LaTeX.

I aimed to finish the discrete maths half of the course in a day, just to see how quickly I could make the document. After all, LaTeX has a steep learning curve, and some people, like me initially, probably have the impression that LaTeX would be slower than other what-you-see-is-what-you-get word processing software. Well, I met my aim.

However, to be fair, discrete maths only involved a lot of equations, which are easy to type up once you’re used to it. Graph theory, the other half of the course however, would definitely take longer due to the diagrams that had to be drawn. Well I *thought* it would take a very long time, but that’s because I only started looking into how to draw LaTeX graphs today.

It’s a shame that I only know a few words of French. At least the code’s in English though

I found out, after some research, that there is a tkz-graph package for LaTeX. It makes graph drawing pretty easy. Installing it took some figuring out, but it turned out that MikTeX has an installer for packages inbuilt, which was very useful.

The good thing about tkz-graph is that you can define vertices, and then reference them when creating edges. I haven’t worked out most of the features yet, but I can make some simple graphs now at least.

Simple graphs.

Here’s the code I used to generate the first of the graphs (the other two are similar):

\begin{minipage}[b]{0.3333\linewidth}
\centering
\begin{tikzpicture}[scale=.5]
SetGraphUnit{2}
\GraphInit[vstyle=Classic]
\tikzset{VertexStyle/.style= {fill=black, inner sep=2pt, shape=circle}}
\begin{scope}[rotate=135]
\Vertices[Lpos=135, unit=2, NoLabel]{circle}{A, B, C, D}
\end{scope}
\Edges(A, B, C, D)
\end{tikzpicture}
\end{minipage}

For those interested, here’s a few quick notes about what I know, and don’t know about the above code:

- The
*\begin{minipage}* is what allows me to show three graphs side by side. Make sure your minipage blocks of code don’t have any empty lines in between them though, or your diagrams will appear under each other as opposed to adjacent (empty lines are like telling LaTeX “I want a new paragraph!”)
- I’ve got
*SetGraphUnit{2}* there, which refers to how far about everything is. However, I’ve also got *unit=2* when defining the vertices – I put that there because for some reason some graphs were turning out smaller than others if I didn’t have it…
- In the
*\tikzset* command, *inner sep=2pt* makes the vertices smaller than their usual size.

- The
*Lpos=135* argument of the *\Vertices* command refers to the positioning of the vertex labels in relation to the vertices (135 degrees rotation). I’ve also set labels off with *NoLabel* though, so it’s not actually doing anything.
*\Edges* draws edges continuously, so *\Edges{A, B, C, D}* draws the edges AB, BC and CD. For a single edge, use *\Edge(A)(B)*.

I’m only just starting out though, so this will get interesting when I have to draw more complex graphs. As a forward reference though, here’s some things I’ll be expecting to use:

- There is a label option for the edges, which will come in handy for weighted graphs.
- tikz supports a
*\foreach* command, which is like a programming for loop for repetitive tasks. This will probably come in useful for drawing complete graphs.