Charts and graphs in LaTeX using PGF / TikZ 3.0

A few months ago, a graphics package for LaTeX PGF / TikZ 3.0 was released, and a lot of interesting things appeared in it. In this article, we will try to apply them to draw a simple flowchart. Let’s draw, for example, a piece of the well - known written language definition scheme . We will not touch the tools already discussed in a previously published article , but let’s talk about simplified notation of graph entries and control of node positioning and graph branching.
Simplified graph notation
The standard commands for drawing nodes and lines in TikZ are
\nodeand \path, but the code with them turns out to be rather verbose and behind the fence from the teams \nodeyou can lose the diagram itself. TikZ 3.0 introduced a simplified graph notation, borrowed from the well-known Graphviz package and its DOT language . In DOT notation, the simplest graph can be written as a sequence of text labels and pseudo-arrows, sort of a -> b -> c. 
Let's start with the preamble:
\usepackage{tikz}
\usetikzlibrary{graphs}
And make a simple graph:
\begin{tikzpicture}
\graph {
Диакритика? -> Да! -> Французский
};
\end{tikzpicture}
The command
\graphin its argument accepts the description of the graph in the DOT notation, and we assume that we will get a chain of three vertices. In reality, it’s not so simple: our labels went astray (point 1 in the “Vertex Chain” picture) You can position the nodes of the graph manually, and we will do this in the next part, but for now try automatic positioning. The simplest thing you can do is tell TikZ in the team options
\graphwhere the graph should grow and where to branch. Let's grow the graph to the right, so that the centers of the nodes are located on the grid with a step of three centimeters (point 2): \begin{tikzpicture}
\graph[grow right=3cm] {
Диакритика? -> Да! -> Французский
};
\end{tikzpicture}
You can specify the distance not between the centers, but between the neighboring edges of the nodes (point 3):
\begin{tikzpicture}
\graph[grow right sep=2em] {
Диакритика? -> Да! -> Французский
};
\end{tikzpicture}
Count can be grown in any direction. The standard directions of right, left, up, down are orthogonal to the coordinate axes, but you can also grow at an angle (point 4):
\begin{tikzpicture}
\graph[chain shift=(-45:1)] {
Диакритика? -> Да! -> Французский
};
\end{tikzpicture}
Free text in tags

If there is, for example, a hyphen in the label, or something else more or less complicated (a mathematical formula?), Then they won’t understand us without additional hints, but if you quote it, everything will be ok:
\begin{tikzpicture}
\graph[grow right sep=1em] {
Диакритика? -> Много над E:\\ \`{E}, \'{E}, \^{E}, \"{E} -> Французский
};
\end{tikzpicture}
\begin{tikzpicture}
\graph[grow right sep=1em] {
Диакритика? -> "Много над E:\\ \`{E}, \'{E}, \^{E}, \"{E}" -> Французский
};
\end{tikzpicture}
Graph branching
Let's make our scheme more complicated and add branching. In DOT notation, nodes can be combined into a group using curly braces and draw an arc from each ancestor node to each of the nodes of the group:
\begin{tikzpicture}
%% Опция nodes определяет параметры всех узлов графа. align=center центрирует текст в узле
\graph[nodes={align=center}, grow down sep, branch right sep] {
Диакритика? ->
{
"Много над E:\\ \`{E}, \'{E}, \^{E}, \"{E}" -> Французский,
Мало -> "Хоть что-то есть?" ->
{
"\c{C} и \"{E}" -> Точно не французский? ->
{
"Ой$\dots$он" -> Французский,
Вроде нет -> Албанский
},
"Только \"{A} и \"{O} \\ но мноогоо \\ сдвооенных" -> Финский
}
}
};
\end{tikzpicture}

As you can see, arcs from the question nodes were drawn to the corresponding answer nodes. The parameter is responsible for the location of nodes during branching
branch, in our case it right sepsays that the branch should go to the right, with the same distance between layers. It can take other values, similar to a parameter grow. By the way, we needed to specify the alignment of the text in the nodes, without which line breaks in labels would not work But we seem to have a problem. The arc from the node "Oh ... he" to the conclusion "French" was conducted, but went somewhere up. Is it possible to make the conclusion “French” be lower than all the questions and answers preceding it? If it is naive to place the conclusion “French” behind the whole group after the question “Diacritics?”, Then the arcs will be drawn from all the leaves of the group:
\begin{tikzpicture}
%% Добавим стиль рисования всех узлов
\graph[nodes={align=center,rectangle,draw=black}, grow down sep, branch right sep] {
Диакритика? ->
{
"Много над E:\\ \`{E}, \'{E}, \^{E}, \"{E}",
Мало -> "Хоть что-то есть?" ->
{
"\c{C} и \"{E}" -> Точно не французский? ->
{
"Ой$\dots$он",
Вроде нет -> Албанский
},
"Только \"{A} и \"{O} \\ но мноогоо \\ сдвооенных" -> Финский
}
} ->
Французский
};
\end{tikzpicture}

But you can explicitly exclude leaves from the list of ends of the drawn arcs by adding the
not sourceand options not target. Their names are somewhat contradictory: so, to indicate that an arc should not go from the Albanian node to the French node, an option should be assigned to the Albanian node[not target] \begin{tikzpicture}
\graph[nodes={align=center,rectangle,draw=black}, grow down sep, branch right sep] {
Диакритика? ->
{
"Много над E:\\ \`{E}, \'{E}, \^{E}, \"{E}",
Мало -> "Хоть что-то есть?" ->
{
"\c{C} и \"{E}" -> Точно не французский? ->
{
"Ой$\dots$он",
Вроде нет -> Албанский[not target]
},
"Только \"{A} и \"{O} \\ но мноогоо \\ сдвооенных" -> Финский[not target]
}
} ->
Французский
};
\end{tikzpicture}
Perhaps enough for the first part, and in the following parts it will be possible to consider other strategies for positioning nodes and options for using DOT notation.
Links:
[1] The source code of the diagrams from the article and the compiled result
[2] PGF / TikZ package