Chapter 9: Creating Graphics

Today, LaTeX provides comprehensive graphic capabilities. In this chapter, we will work on some impressive graphics.

Specifically, this chapter covers the following recipes:

Introduction

A picture is worth a thousand words. By presenting a single image, you can visualize a complex concept and it becomes much easier to understand. Especially using diagrams, you can distill relevant information and, for example, show relationships and processing orders or compare quantities.

This chapter mainly contains recipes for several kinds of diagrams. Some further useful graphics recipes round it off.

All the recipes in this chapter are based on pgf/TikZ, which is an enormously capable graphics package. pgf stands for Portable Graphics Format, which is the backend. TikZ is the frontend. The name is an abbreviation of TikZ ist kein Zeichenprogramm, which translates to “TikZ is not a drawing program.” This recursive acronym, created in the tradition of GNU, should tell potential users what to expect: no WYSIWYG. This means that you cannot see the output during creation, but after compiling. However, with TikZ, you benefit from TeX’s strong points: fine quality, macros, reusability, and a large number of existing libraries and packages.

There’s another very capable graphics package for LaTeX with a long history and countless features—PSTricks. It is based on PostScript, which can be translated into PDF. In this chapter, we will take the TikZ way, because of its very readable syntax, excellent documentation, and compatibility with all TeX engines (pdfTeX, XeTeX, and LuaTeX) and formats (LaTeX, plain TeX, and ConTeXt). Last but not least, the decision is led by a view of the growing popularity of TikZ in Internet forums over the years, which can also be verified using a Google Trends search.

We won’t deal with how to draw rectangles or circles, since this is covered by the manual. Instead, we will start off by using modern packages for various purposes to create complete and useable graphics.

Getting ready

To compile the recipes in this chapter, you need to have TikZ installed. Note that while the name is the popular one, the actual package name is pgf, which you can see in the package manager of your LaTeX installation. Version 3.0 or later is recommended. Most recipes use another package on top of TikZ. So, for each package mentioned at the beginning of a recipe, make sure you have it installed. A full TeX installation is recommended anyway. In order to cover many complete and usable recipes in this chapter about graphics, the basic TikZ commands will not be explained. You can read about them in the reference manual at any time. It’s assumed that you already know something about nodes, edges, and styles; take a look at the manual if you need to understand those concepts. Of course, it’s explained in detail how the recipes themselves work. So, for further customization and a deeper understanding, keep the TikZ manual at hand. You can simply open it by typing texdoc tikz or texdoc pgf in the command line. The same applies to each used package.

If you are reading this book without having a TeX installation with documentation available, visit https://texdoc.org/pkg/tikz.

Navigate: