Chapter 1 – Getting started with TikZ

Here are the Code examples of this chapter. You can compile them online right on this web page by pressing the Typeset / Compile button. You can also edit them for testing, and compile again.

For a better view with the online compiler, I use \documentclass[border=10pt]{standalone} instead of \documentclass{article}. Instead of having a big letter/A4 page, the standalone class crops the paper to see just the visible text without an empty rest of a page.

Any question about a code example? Post it on LaTeX.org, I will answer. As forum admin I read every single question there. (profile link).

Classic picture mode example

\documentclass[border=10pt]{standalone}
\begin{document}
\setlength{\unitlength}{1cm}
\begin{picture}(1,1)
  \put(0,0){\circle{1}}
  \put(-0.5,0){\line(1,0){1}}
  \put(-0.3,0.06){text}
\end{picture}
\end{document}

First TikZ drawing

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{quotes}
\begin{document}
\begin{tikzpicture}
\draw circle (0.5);
\draw (-0.5,0) to ["text"] (0.5,0);
\end{tikzpicture}
\end{document}