Reader small image

You're reading from  LaTeX Graphics with TikZ

Product typeBook
Published inJun 2023
PublisherPackt
ISBN-139781804618233
Edition1st Edition
Tools
Right arrow
Author (1)
Stefan Kottwitz
Stefan Kottwitz
author image
Stefan Kottwitz

Stefan Kottwitz studied mathematics in Jena and Hamburg. He works as a network and IT security engineer both for Lufthansa Industry Solutions and for Eurowings Aviation. For many years, he has been providing LaTeX support on online forums. He maintains the web forums LaTeX and goLaTeX and the Q&A sites TeXwelt and TeXnique. He runs the TeX graphics gallery sites TeXample, TikZ, and PGFplots, the TeXlive online compiler, the TeXdoc service, and the CTAN software mirror. He is a moderator of the TeX Stack Exchange site and matheplanet. He publishes ideas and news from the TeX world on his blogs LaTeX and TeX. Before this book, he authored the first edition of LaTeX Beginner's Guide in 2011, and LaTeX Cookbook in 2015, both published by Packt.
Read more about Stefan Kottwitz

Right arrow

Drawing Diagrams

As well as standard documents, presentation slides and conference posters often utilize diagrams to represent information visually. This chapter shows you how to create various kinds of diagrams with TikZ.

In this chapter, we’ll be covering the following topics:

  • Creating flowcharts
  • Building relationship diagrams
  • Writing descriptive diagrams
  • Producing quantitative diagrams

As you already have the tools to create diagrams manually using nodes, styles, positioning, and arrows, this chapter focuses on packages that generate whole diagrams.

Once you have mastered this chapter, you can create colorful and visually stunning diagrams in any context.

Technical requirements

You can find the code examples for this chapter at https://tikz.org/chapter-14. On GitHub, you can download them at https://github.com/PacktPublishing/LaTeX-graphics-with-TikZ/tree/main/14-diagrams.

We will use the following packages: smartdiagram, sansmath, pgf-pie, wheelchart, and fontawesome5.

Creating flowcharts

If we want to illustrate a process or a workflow, we can create a flowchart. Such a diagram consists of nodes that represent, for example, process steps or decision points and arrows that indicate the process flow. We produced our first flowchart in Chapter 4, Drawing Edges and Arrows. Our result was Figure 4.6.

This section will look into a handy package that provides quick ways to create flowcharts and other diagrams easily. That package is called smartdiagram, and it truly deserves this name. Just look at how fast we can create a flowchart with just a few lines of code now.

First, we have to load the package:

\usepackage{smartdiagram}

It comes with a \smartdiagramset command that is used to customize the diagrams, and it works similarly to \tikzset and \pgfplotsset, except it is just for smart diagrams. For example, I strongly prefer sans-serif text in diagram nodes, so I can use the following command to get a sans-serif font in a diagram:

\smartdiagramset...

Building relationship diagrams

In Chapter 6, Drawing Trees and Graphs, we encountered a special relationship diagram, the mind map. The smartdiagram package offers other diagram types that indicate connections between concepts or objects. Such diagrams are naturally not linear – for example, a mind map can be very complex, such as in Figure 6.15.

Since they are focused and aesthetically pleasing, we will focus on circular relationship diagrams, which have a central concept and related concepts placed around them.

Our first diagram type shall be a bubble diagram. It’s like a mind map – there is a central concept or object, and related concepts are placed around it in a circular manner and shape. The following code illustrates it:

\smartdiagramset{bubble node font=\sffamily\LARGE,
  bubble center node font=\sffamily\Huge}
\smartdiagram[bubble diagram]{Diagrams,
    Nodes, Edges, Arrows, Labels, Colors}

This code generates...

Writing descriptive diagrams

A descriptive diagram typically represents terms and explanations and connects or aligns them for illustration.

You know the standard LaTeX description environment. Let’s create a diagram in a similar layout to make it visually stunning.

First, we choose the fonts, a very large font for the items and a small font for each description, all in sans-serif font:

\smartdiagramset{description title font=\sffamily\LARGE,
  description font=\sffamily\footnotesize}

Now, we use the descriptive diagram type of smartdiagram and give a list of pairs of titles and descriptions, each pair in braces. Remember, since the comma is used to separate list items, we have to use additional braces if a description contains a comma itself. Also, end the list with a comma, since smartdiagram uses it to properly parse all items. We can come up with a code to describe PGF and TikZ:

\smartdiagram[descriptive diagram]{
  {PGF, {Portable Graphics...

Producing quantitative diagrams

Until now, our diagrams presented objects in order or in relation to each other. Now, we will visualize and compare actual values utilizing diagrams.

Line charts

Numerical data is often a series of values measured over time. These values can be displayed as data points on a plane, with the x axis for the time and the y axis for the values. Connecting lines show the trend over time. This is called a line chart. Such a chart can contain multiple line series to display different datasets to see them in relation. The x axis doesn’t need to represent time; it could be any other base value, such as age, weight, or other data to correlate with values.

In Figure 12.5, we saw how a line chart could be plotted, and Chapter 13, Plotting in 2D and 3D, showed tools to plot in a coordinate system. pgfplots provides a perfect setting to display values in a plane by lines or bars with annotations.

This section will compare the graphics packages TikZ...

Summary

This chapter covered a wide range of diagram types with many examples that can be the foundation for your diagrams.

You learned to quickly create flowcharts, perfect for breaking down complex processes into easy-to-follow steps. With relationship diagrams, you can now visualize the connections and relationships between different concepts. Your descriptive diagrams can make your ideas easier to understand. With quantitative charts, you can showcase your data in the best way to visualize and compare values.

With the diagram tools you studied in this chapter and the TikZ knowledge you acquired while reading this book, you are ready to create beautiful and informative graphic illustrations for your documents.

After all this hard work, you deserve some fun. That shall be the motto for the next chapter!

Further reading

The smartdiagram package provides a detailed manual with a complete reference to all settings and even its source code. You can open it on your computer at the command line with texdoc smartdiagram or by visiting https://texdoc.org/pkg/smartdiagram.

The LaTeX Cookbook by Packt Publishing and written by me has a Building smart diagrams section in Chapter 9, Creating Graphics. It shows more smartdiagram examples, just not as customized as in this chapter, and with detailed explanations and references. You can find the entire section at https://latex-cookbook.net/9-1-building-smart-diagrams/.

The LaTeX Cookbook explains in detail how to create a complex flowchart from scratch with just standard TikZ tools. This section is also available online; you can read it at https://latex-cookbook.net/9-2-constructing-a-flowchart. You can also find pie charts and Venn diagrams examples in the same book and on its website.

The pgf-pie manual can be found at https://texdoc...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
LaTeX Graphics with TikZ
Published in: Jun 2023Publisher: PacktISBN-13: 9781804618233
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Stefan Kottwitz

Stefan Kottwitz studied mathematics in Jena and Hamburg. He works as a network and IT security engineer both for Lufthansa Industry Solutions and for Eurowings Aviation. For many years, he has been providing LaTeX support on online forums. He maintains the web forums LaTeX and goLaTeX and the Q&A sites TeXwelt and TeXnique. He runs the TeX graphics gallery sites TeXample, TikZ, and PGFplots, the TeXlive online compiler, the TeXdoc service, and the CTAN software mirror. He is a moderator of the TeX Stack Exchange site and matheplanet. He publishes ideas and news from the TeX world on his blogs LaTeX and TeX. Before this book, he authored the first edition of LaTeX Beginner's Guide in 2011, and LaTeX Cookbook in 2015, both published by Packt.
Read more about Stefan Kottwitz