Samuel Ireson

Learning TikZ - Episode 1

Sat Feb 24 2024
2 min read

We'll walk through how I made a figure to visualise Hausdorff spaces in TikZ.

Contents

Introduction

TikZ is a LaTeX library which allows you to draw diagrams, figures, graphs, and anything else which you can think up. It’s my go-to for drawing complex diagrams because of it’s reliance on declarative nature. Also, the implementation of the commands is very neat, and natural.

Setup

The minimal setup for creating a TikZ figure is as follows,

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
    % TikZ goes here.
\end{document}

which will output a .pdf file, with minimal dimensions. You can include the graphics generated in a master file with the \includegraphics{} command.

Figure

Knowing the mathematical significance of Hausdorff spaces is not a pre-requisite for learning TikZ, so just believe me that the figure we will produce is useful in the visualisation of such spaces.

We start with a rounded box which will act as our topological space, and label this by X.

\draw plot[smooth cycle] coordinates {(-1,-1) (1,-1) (1,1) (-1,1)};
\node[above left] at (-1,1) {$ X $};

Rounded space

Then define nodes at two points in the space.

\coordinate (u) at (0.2,0.7);
\coordinate (v) at (-0.5, -0.2);
\fill (u) circle (0.05) node[below]{$ u $};
\fill (v) circle (0.05) node[below]{$ v $};

Rounded space with points

You might think that defining coordinates is overkill here, but I think that the flexibility that this gives you down the line is worth the verbosity. We now draw open sets around these points.

\filldraw[dashed, fill=gray!50, fill opacity=0.5] (u) circle (0.4);
\filldraw[dashed, fill=gray!50, fill opacity=0.5] (v) circle (0.4);

Open sets around the points

And reorder the code to place the labels above these open sets.

\filldraw[dashed, fill=gray!50, fill opacity=0.5] (u) circle (0.4);
\filldraw[dashed, fill=gray!50, fill opacity=0.5] (v) circle (0.4);

\fill (u) circle (0.05) node[below]{$ u $};
\fill (v) circle (0.05) node[below]{$ v $};

A Hausdorff space has non-intersecting open sets around all points!

Conclusion

That’s it! Our open sets don’t intersect, and this gives a good depiction for what it means for a space to be Hausdorff.

Related posts