Search icon CANCEL
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Learning Hub
Free Learning
Arrow right icon
LaTeX Graphics with TikZ
LaTeX Graphics with TikZ

LaTeX Graphics with TikZ: A practitioner's guide to drawing 2D and 3D images, diagrams, charts, and plots

$35.99 $24.99
$15.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon AI Assistant (beta) to help accelerate your learning
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now
Table of content icon View table of contents Preview book icon Preview Book

LaTeX Graphics with TikZ

Getting Started with TikZ

First, congratulations on using LaTeX! You have already chosen an excellent tool for writing, and now you are ready to add high-quality figures to your documents.

To work with this book, you should have a good understanding of LaTeX and know how to work with a LaTeX editor and compiler. If you are still learning about LaTeX, here are two recommended books:

  • The LaTeX Beginner’s Guide, Second Edition by Packt Publishing gives you a fast start; you can find more information about it at
  • The LaTeX Cookbook by Packt Publishing offers many ready-to-use examples for various document types. Look at the book’s website at

This chapter shall be a quickstart. We will cover the following topics:

  • What is TikZ?
  • Alternative graphics packages
  • Benefits of TikZ
  • Installing TikZ
  • Working with TikZ documentation
  • Creating our first TikZ figure

We will briefly look...

Technical requirements

You need to have a LaTeX distribution installed on your computer, for example, TeX Live (, MacTeX (, or MiKTeX ( A full installation is recommended. It may take up to 8 GB of space on your hard disk, but you don’t need to worry about missing packages.

Alternatively, you can use Overleaf ( It’s an excellent online LaTeX editor and compiler; that’s why it requires a permanent internet connection to be able to use it.

All code examples of this chapter are available on GitHub at

At, you can also find all code examples from this book. You can edit and compile to PDF directly on that website, so you can even use a smartphone or tablet to work with this book’s code.

What is TikZ?

The inventor of TikZ, Till Tantau, created the name as a recursive acronym in German. TikZ stands for TikZ ist kein Zeichenprogramm, which translates to TikZ is not a drawing program. It’s Tantau’s jokey way of emphasizing that you cannot expect to draw with it like with a pen or just mouse clicks, such as with Microsoft Paint on Windows, Paintbrush on a Mac, Adobe Illustrator Draw, or the free Inkscape vector graphics editor.

Simply said, TikZ is a set of TeX commands for drawing graphics. Just like LaTeX is code that describes a document, TikZ is code that describes graphics and looks like LaTeX code. With TikZ, you write \draw [blue] circle (1cm); to get a blue circle with a 1 cm radius in your PDF document.

The origin of TikZ is called PGF, which stands for Portable Graphics Format and is a set of graphics macros that can be used with pdfLaTeX and the classic DVI/PostScript-based LaTeX. Today, we consider TikZ as the frontend and PGF as the backend...

Alternative graphics packages

Before we start, let’s quickly look at where we come from and what else is out there.

The LaTeX picture environment

LaTeX itself defines some basic graphics commands. We can use a picture environment for this.

To get an idea of how it works, let’s have a quick look at a minimal example:


The output is the following:

Figure 1.1 – A classic LaTeX picture drawing

Figure 1.1 – A classic LaTeX picture drawing

Here, we did the following:

  1. We set a base length. All numbers in drawing commands are seen as multiples of this base unit length.
  2. We used \put(x,y){…} to put something at the Cartesian coordinate position x, y.
  3. We wrote \circle{x} to get a circle with a diameter of x times the unit length.
  4. We used \line(x,y){z} to get a line in vector direction...

Benefits of TikZ

Compared to classic drawing programs where you click with the mouse on shapes and toolbars and drag and drop graphic elements, TikZ is very different. With TikZ, you program graphics with code.

That means your graphics will be the following:

  • Precise: You get the exact placement of graphic and text elements using anchors, baselines, alignment, relative positioning, and implicit coordinate calculations.
  • Consistent: TikZ blends in perfectly with LaTeX. You can use LaTeX fonts, symbols, formulas, colors, and macros within your drawing, and your drawing details will precisely match your LaTeX document design. That would be different if you imported some externally made images.
  • High-quality: TikZ generates scalable PDF images that look fine when you zoom in or out. There are no blurry or pixelated images.
  • Efficient: Similar figures mean similar code and similar styles; it’s all reusable, and when you adjust global styles, you change the appearance...

Installing TikZ

As you already have LaTeX installed, you just need to ensure that the pgf and xcolor packages are installed. You can install them in three main ways, which are discussed in the following sub-sections.

With a vanilla TeX distribution

If you installed LaTeX from DVD or via the internet from an original TeX distribution, use its package manager to install the pgf and xcolor packages. These are the three principal TeX distributions, along with installation details:

  • TeX Live: Start TeX Live Manager (tlmgr or tlshell), then search and install the pgf and xcolor packages
  • MiKTeX: Use the MiKTeX package manager (mpm) to install pgf and xcolor
  • MacTeX: Use TeX Live Utility to install pgf and xcolor

When you want to update TikZ later on, run your regular TeX distribution updates, and pgf will be updated as well.

With an operating system TeX installation

If your LaTeX installation comes from your operating system repositories, which is usually...

Working with the TikZ documentation

The LaTeX and TikZ installations contain documentation. You can access it in the following two ways:

  • Windows: Run the cmd app via the Start menu
  • Apple macOS or Linux: Open a terminal window

Then, type this command:

texdoc tikz

Your PDF viewing app will open and display the TikZ manual in all its 1,300-page size and glory. But don’t feel intimidated, for the following reasons:

  • It’s good to have so many features so well documented in a huge reference with an extensive index, hyperlinks, full-text search, and of course, a lot of examples.
  • Hundreds of pages are about the PGF backend, the basic layer, and the system layer on the driver level. You don’t need that as a user.
  • It describes all additional libraries and utilities.
  • It contains five tutorials.

I hope that in the future, this manual will be split into a TikZ manual, a PGF backend reference for developers, and tutorials.


Creating our first TikZ figure

Our first goal is to create a TikZ drawing that is the same as Figure 1.1, which we made in the classic LaTeX picture mode, to get a feeling of the TikZ basics.

To be able to use TikZ, you need to perform the following three steps:

  1. Load the tikz package in your document preamble:
  2. TikZ provides additional features with separate libraries. Here, we load the quotes library for adding annotations with an easy quoting syntax that we will use in the drawing:
  3. Use a tikzpicture environment for the drawing. The first code snippet we saw in this chapter, for the picture environment, will look like this with TikZ:
      \draw circle (0.5);
      \draw (-0.5,0) to ["text"] (0.5,0);

This results in the following output:

Figure 1.2 – Our first TikZ drawing

Figure 1.2 – Our first TikZ drawing

We draw a circle with a radius of 0.5 cm at the default...


In this chapter, we learned what TikZ is, how to install it, and how to access the documentation. We had a first glimpse at the syntax and created our first TikZ figure of the book. Rest assured, there are many more to come!

In the coming chapters, we will learn more about TikZ commands, objects, and styles, to create more fancy drawings. In the next chapter, we’ll learn about the essential toolbox, with coordinates, paths, colors, lines, circles, and other curves and shapes.

Further reading

The TikZ manual is an excellent and comprehensive reference book. We will refer to it many times. You can find the manual at in PDF format and at in handy reflowable HTML sections, which makes it easier to read on a smartphone or tablet.

The LaTeX Graphics Companion by Michel Goossens, Frank Mittelbach, et al. is a comprehensive book about creating LaTeX graphics. With the first edition published in 1997 and the second and latest edition published in 2007, it doesn’t cover the newest developments, even though there’s a reprint of the second edition from 2022. When I bought the reprint and noticed that TikZ is completely missing in that book, I decided to write the book you hold in your hand now.

PSTricks: Graphics and PostScript for TeX and LaTeX by Herbert Voss is a great reference book specifically about PSTricks with many examples.

MetaPost: Grafik für TeX und LaTeX by Walter Entenmann is a...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Achieve native construction of images and diagrams in your LaTex theses, articles, or books with enhanced quality
  • Discover comprehensive explanations and real-world use cases to apply in your own endavors
  • Explore customizations and tweaks to grasp the synergy of LaTeX and TikZ graphics


In this first-of-its-kind TikZ book, you’ll embark on a journey to discover the fascinating realm of TikZ—what it’s about, the philosophy behind it, and what sets it apart from other graphics libraries. From installation procedures to the intricacies of its syntax, this comprehensive guide will help you use TikZ to create flawless graphics to captivate your audience in theses, articles, or books. You’ll learn all the details starting with drawing nodes, edges, and arrows and arranging them with perfect alignment. As you explore advanced features, you’ll gain proficiency in using colors and transparency for filling and shading, and clipping image parts. You’ll learn to define TikZ styles and work with coordinate calculations and transformations. That’s not all! You’ll work with layers, overlays, absolute positioning, and adding special decorations and take it a step further using add-on packages for drawing diagrams, charts, and plots. By the end of this TikZ book, you’ll have mastered the finer details of image creation, enabling you to achieve visually stunning graphics with great precision.

What you will learn

Understand the TikZ language and how to use its libraries and packages Draw geometric shapes with text and add arrows, labels, and decorations Apply transformations and use transparency, shading, fading, and filling features Define styles and program with loops to streamline your code Build trees, graphs, and mind maps and draw easy curves with smooth transitions Produce block diagrams and flow charts to visualize process steps Generate line charts and bar charts to showcase your data Plot data sets and mathematical functions in two and three dimensions

Product Details

Country selected

Publication date : Jun 9, 2023
Length 304 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781804618233
Category :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon AI Assistant (beta) to help accelerate your learning
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details

Publication date : Jun 9, 2023
Length 304 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781804618233
Category :

Table of Contents

18 Chapters
Preface Chevron down icon Chevron up icon
1. Chapter 1: Getting Started with TikZ Chevron down icon Chevron up icon
2. Chapter 2: Creating the First TikZ Images Chevron down icon Chevron up icon
3. Chapter 3: Drawing and Positioning Nodes Chevron down icon Chevron up icon
4. Chapter 4: Drawing Edges and Arrows Chevron down icon Chevron up icon
5. Chapter 5: Using Styles and Pics Chevron down icon Chevron up icon
6. Chapter 6: Drawing Trees and Graphs Chevron down icon Chevron up icon
7. Chapter 7: Filling, Clipping, and Shading Chevron down icon Chevron up icon
8. Chapter 8: Decorating Paths Chevron down icon Chevron up icon
9. Chapter 9: Using Layers, Overlays, and Transparency Chevron down icon Chevron up icon
10. Chapter 10: Calculating with Coordinates and Paths Chevron down icon Chevron up icon
11. Chapter 11: Transforming Coordinates and Canvas Chevron down icon Chevron up icon
12. Chapter 12: Drawing Smooth Curves Chevron down icon Chevron up icon
13. Chapter 13: Plotting in 2D and 3D Chevron down icon Chevron up icon
14. Chapter 14: Drawing Diagrams Chevron down icon Chevron up icon
15. Chapter 15: Having Fun with TikZ Chevron down icon Chevron up icon
16. Index Chevron down icon Chevron up icon
17. Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(3 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by

Thomas Schlusnath Oct 16, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book is excellent to get a good understanding about the concept behind TikZ and pgf. I used LaTex and TikZ in a way of copy and paste from different websites but had no deeper understanding of TikZ. The TikZ manual is excellent, of course, but as a beginner you get lost in the level of details provided. Mr.Kottwitz book fills the gap of an easy-to-learn introduction to TikZ and will enable me to work successful with the TikZ manual.
Feefo Verified review Feefo image
Joseph Lucke Feb 16, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The ebook is very large. This makes it hard to access on any device without substantial memory. Perhaps there is a remedy for this problem.
Feefo Verified review Feefo image
davide bondoni Dec 28, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo image
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial


How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to
  • To contact us directly if a problem is not resolved, use
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.