\node
and \path
, but the code with them is quite verbose and you can lose the diagram itself behind the fence from the \node
commands. In TikZ 3.0, a simplified notation for graphs appeared, borrowed from the famous Graphviz package and its DOT language . In the DOT notation, the simplest graph can be written as a sequence of text labels and pseudo arrows, like a -> b -> c
. \usepackage{tikz} \usetikzlibrary{graphs}
\begin{tikzpicture} \graph { ? -> ! -> }; \end{tikzpicture}
\graph
in its argument takes the description of the graph in the DOT notation, and we assume that we will get a chain of three vertices. In reality, not everything is so simple: our tags got lost in the Kuchamalu (point 1 in the picture “The Chain of Summits”)\graph
command \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 in increments of three centimeters (point 2): \begin{tikzpicture} \graph[grow right=3cm] { ? -> ! -> }; \end{tikzpicture}
\begin{tikzpicture} \graph[grow right sep=2em] { ? -> ! -> }; \end{tikzpicture}
\begin{tikzpicture} \graph[chain shift=(-45:1)] { ? -> ! -> }; \end{tikzpicture}
\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}
\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}
branch
parameter is responsible, in our case, right sep
says that the branching should go to the right, with the same distance between the layers. It can take other values, similar to the grow
parameter. By the way, we needed to specify the alignment of the text in the nodes, without which line breaks in the labels would not work \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}
not source
and not target
. Their names are somewhat contradictory: in order to indicate that an arc should not go from the “Albanian” node to the “French” node, the [not target]
option should be assigned to the “Albanian” node \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}
Source: https://habr.com/ru/post/224501/
All Articles