Chapter 1 – Getting Started with TikZ

Here are the Code examples of this chapter. These pages are currently being updated over time (adding pictures, captions, and possibly further examples). Visit again soon for updates. Of course, the best way to use this page is together with the book for getting the explanations.


figure

Figure 1.1 – A classic LaTeX picture drawing

\documentclass[border=30pt]{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}


figure

Figure 1.2 – Our 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}

Not that if you load the babel package with activated shorthand ” for German umlauts/accents such as in “Schön”, you may need to disable it to use the quotes syntax, either before or within the TikZ picture. For example:

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

Go to next chapter.