# How to create the following figures in TikZ

I'd like to create the following two figures with TikZ

I'm tikz beginner, can anybody give me some advice how to do that?

Now i've created the first figure:

\documentclass[border=5pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix, positioning, fit}
\begin{document}
\begin{tikzpicture}[
mymatrix/.style={matrix of nodes, nodes=typetag, row sep=1em, anchor=base},
mycontainer/.style={draw=black,inner sep=1ex},
typetag/.style={draw=black, inner sep=1ex, anchor=west},
title/.style={draw=none, color=black, inner sep=0pt}
]
\matrix[mymatrix] (mx1) {
|[title]|Text A \\
Text 1 \\
Text 2 \\
Text 3 \\
Text 4 \\
Text 5 \\
Text 6 \\
};
\matrix[mymatrix, right=of mx1.north east, matrix anchor=north west] (mx2) {
|[title]|Text D \\
Text 13 \\
Text 14 \\
Text 15 \\
Text 16 \\
Text 17 \\
Text 18 \\
};
\matrix[mymatrix, right=of mx2.north east, matrix anchor=north west] (mx3) {
|[title]|Text E \\
Text 19 \\
};
\matrix[mymatrix, above=of mx2.north, matrix anchor=south west] (mx4) {
|[title]|Text C \\
Text 12 \\
};
\matrix[mymatrix, above=of mx2.north, matrix anchor=south east] (mx5) {
|[title]|Text B \\
Text 7 \\
Text 8 \\
Text 9 \\
Text 10 \\
Text 11 \\
};

\node[mycontainer, fit=(mx1)] (n1) {};
\node[mycontainer, fit=(mx2)] (n2) {};
\node[mycontainer, fit=(mx3)] (n3) {};
\node[mycontainer, fit=(mx4)] (n4) {};
\node[mycontainer, fit=(mx5)] (n5) {};

\path[->,thick] (n1) edge (n2);
\path[->,thick] (n3) edge (n2);
\path[->,thick] (n4) edge (n2);
\path[->,thick] (n5) edge (n2);
\end{tikzpicture}
\end{document}


As already mentioned I'm a TikZ beginner, so there are the following problems:

1. How can the boxes around "Text 1", "Text 2" and so on have the same width and height? I'd like to have them centered, too.
2. How can I create the arrows look like in the sample picture? Actually they seem badly arranged.
3. How can I create the black boxes like in the sample picture?
4. Is it the right way to use matrix to create this figure, could it be done easier?

Here is the LaTeX-code for the second figure:

\documentclass[tikz,border=5pt]{standalone}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}
%
\usepackage{tikz}
\usetikzlibrary{matrix,positioning-plus}

\begin{document}
\begin{tikzpicture}[
kreis/.style={circle,draw,minimum width=20pt},
every node/.style={align=center}]

\matrix(mat)[row sep=10pt, column sep=60pt] at (0,0) {
\node[kreis](k1) {}; &
\node[kreis](k2) {}; &
\node[kreis](k3) {}; &
\node[kreis](k4) {}; &
\node[kreis](k5) {}; &
\node[kreis](k6) {}; \\
};

\draw[-latex] (k1) -- (k2);
\draw[-latex] (k2) -- (k3);
\draw[-latex] (k3) -- (k4);
\draw[-latex] (k4) -- (k5);
\draw[-latex] (k5) -- (k6);

\node [below,text width=2.5cm,font=\small] at (k1.south) {Text 1};
\node [below,text width=2.5cm,font=\small] at (k2.south) {Text 2};
\node [below,text width=2.5cm,font=\small] at (k3.south) {Text 3};
\node [below,text width=2.5cm,font=\small] at (k4.south) {Text 4};
\node [below,text width=2.5cm,font=\small] at (k5.south) {Text 5};
\node [below,text width=2.5cm,font=\small] at (k6.south) {Text 6};

\node (n1) [above=of k1] {};
\node (n2) [above=of k2] {};
\node (n3) [above=of k3] {};
\node (n4) [above=of k4] {};
\node (n5) [above=of k5] {};
\node (n6) [above=of k6] {};

\draw[latex-latex] (n1) -- (n2) node[midway,above] {Text 7};
\draw[latex-latex] (n2) -- (n3) node[midway,above] {Text 8};
\draw[latex-latex] (n3) -- (n4) node[midway,above] {Text 9};
\draw[latex-latex] (n4) -- (n5) node[midway,above] {Text 10};
\draw[latex-latex] (n5) -- (n6) node[midway,above] {Text 11};

\node (m1) [above=of n1] {};
\node (m5) [above=of n5] {};
\node (m6) [above=of n6] {};

\draw[latex-latex] (m1) -- (m5) node[midway,above] {Text 12};
\draw[latex-latex] (m5) -- (m6) node[midway,above] {Text 13};

\node (k1) [above=of m1] {};
\node (k6) [above=of m6] {};

\draw[latex-latex] (k1) -- (k6) node[midway,above] {Text 14};

\end{tikzpicture}
\end{document}


Actually I have the following problems with it:

1. The arrows above the circles are to short, how can I adjust them?
2. The text above the arrows is not vertically centered, what can I do here?
3. How can I add vertical lines like in the picture above?

Another Question belongs to posting, how can I quickly generate and present a picture of my code?

-
These are not terribly difficult diagrams to create. Perhaps some time with the TikZ tutorials would allow you to make a good beginning attempt and then you could ask questions when you get stuck. – Alan Munn Nov 19 '13 at 20:33
Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – Jubobs Nov 19 '13 at 21:02
Thanks for the advice, i will try to create the examples. – wittmaan Nov 19 '13 at 21:10
1. Easy, see Dependent node size in TikZ and linked question. 2. Easy, can be solved with coordinate specification shortcuts |-/-|, see for example the very last code sample of this answer. 4. A matrix is very good for this kind of picture. You don’t even need the fit library for the simple matrices as you can use options like draw on matrices, too. 3. Matrices cannot be nested (“yet”), TikZ pictures can be nested (but not very nice). A manual approach, maybe? How important is that for you? – Qrrbrbirlbel Nov 20 '13 at 10:37
On that note: 1. Use coordinates instead of nodes. 3. Use the |< and >| arrow combination (see also [1]). 2. I don’t understand. Vertically centered? There are all one-liners. Though, I would add text depth=+0pt to those nodes. For multi-lined nodes this will need more information and really a separate question. (Possibly related: [2] and linked, [3]) – Qrrbrbirlbel Nov 21 '13 at 21:17

For the first problem, nodes having the same size, see Dependent node size in TikZ (which solution I am going to use) and the linked questions which comes down to identifying the widest/tallest/deepest element and giving its measurements as options to the nodes (see text width, text height and text depth). I am using my node-families library from the linked question/answer.

The second problem, better connections between the matrices, see for example the very last example of my answer to Converging and diverging nodes in a flowchart and many others that use (angle) anchors and |-/-| as coordinate specifications. I am going to use a specific mix which includes the use of my paths.ortho library.

Your fourth point, regarding the use of matrices, I think that this is a good example to use matrices, even though we only have one column per matrix. For more complicated stuff and maybe even the matrices with the bold black border, one can use a combination of the fit and the backgrounds library. For examples see my answers [1] and [2].

Now, the black borders will require work. I am using here a solution that first places the fully filled node (Mikro- and Makroebene), and then adds a matrix directly below it which both are then fitted with a node that is only used for the drawn line around it.

There are many different approaches possible for this problem. It is our advantage that these problematic matrices are only placed in the lower row of all matrices and only to the right of other matrices. Note the xshift and yshift in the Title style. If you want to place it to the left, you need to use a negative yshift value (well, at least if you want to use the “correct” node distance). If you want to place such matrices above other nodes/matrices, you better first place the matrix part of this structure (then with a positive yshift for correction of the black border) and then the Title above it (but then without any shifting values).

My positioning-plus library adds another set of …=of … keys to the positioning library (and also loads fit). This introduces the north right=of <ref-node> key that basically is the same as right=of <ref-node>.north east, anchor=north west.

This library also allows us to use x_node_dist and y_node_dist as a reference to the node distances that is set with the node distance key.

## Code

\documentclass[tikz,border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix, positioning-plus, node-families, paths.ortho}
\tikzset{
matrix inner xsep/.style={
/tikz/every node/.append style/.expanded={inner xsep={\pgfkeysvalueof{/pgf/inner xsep}}},
/pgf/inner xsep={#1}},
matrix inner ysep/.style={
/tikz/every node/.append style/.expanded={inner ysep={\pgfkeysvalueof{/pgf/inner ysep}}},
/pgf/inner ysep={#1}},
matrix inner sep/.style={matrix inner xsep={#1}, matrix inner ysep={#1}},
}
\begin{document}
\begin{tikzpicture}[
my matrix*/.style={
matrix inner sep=+1em,
matrix of nodes,
nodes={typetag, Minimum Width=m, text depth=+0pt},
row sep=+.5em,
Minimum Width=M},
my matrix/.style={
my matrix*, draw,
row 1/.append style={nodes=title}},
title/.style={draw=none, font=\bfseries},
Title/.style={
title,
outer sep=+0pt,
Minimum Width=M,
fill, text=white,
text depth=+0pt,
yshift=+-.25cm,
xshift=+.25cm,
inner ysep=.5em},
fitty/.style={fit=(#1')(#1''), line width=+.25cm, inner sep=+.125cm, draw, name=#1},
typetag/.style={draw=black, inner sep=1ex, align=center},
]

\matrix[my matrix] (mx1) {
Text A \\
Text 1 \\
Text 2 \\
Text 3 \\
Text 4 \\
Text 5 \\
Text 6 \\
};
\node[Title, north right=of mx1] (mx2') {Text D};
\matrix[my matrix, below=+0pt of mx2'] (mx2'') {
\node {Text ABC};\\
Text 13 \\
Text 14 \\
Text 15 \\
Text 16 \\
Text 17 \\
\node{Text 18}; \\
};
\node[fitty=mx2]{};
\node[Title, north right=of mx2] (mx3') {Text E};

\matrix[my matrix*, below=+0pt of mx3'] (mx3'') {Text 19 \\};
\node[fitty=mx3] {};

\matrix[my matrix, above=of mx2.north, matrix anchor=south east, shift=(left:.5*x_node_dist)] (mx5) {
Text B \\
\node{Text 7}; \\
Text 8 \\
Text 9 \\
\node{Text 10}; \\
Text 11 \\
};
\matrix[my matrix, north right=of mx5] (mx4) {
Text C \\
\node {Text 12}; \\
};

\path [thick, ->, >=latex]
{
[to path={([shift=(down:y_node_dist)]\tikztostart.north east) -- ([shift=(down:y_node_dist)]\tikztotarget.north west)}]
(mx1) edge     (mx2)
(mx2) edge[<-] (mx3)
}
[|*] ([shift=(left:x_node_dist)]  mx5.south east) edge (mx2)
([shift=(right:x_node_dist)] mx4.south west) edge (mx2)
;
\end{tikzpicture}
\end{document}


## Output

-
Thank You very much, that is, what I was looking for. Sorry for being not fast ennough to say, that the black borders are nice, but not important. – wittmaan Nov 20 '13 at 12:02

Since you already have the two PDF files (fig_process and fig_steps), it is very easy:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\node[inner sep=0] {\includegraphics{fig_process}};
\end{tikzpicture}
\begin{tikzpicture}
\node[inner sep=0] {\includegraphics{fig_steps}};
\end{tikzpicture}
\end{document}

-
+1 This is the best answer on "Please, draw it for me" questions I've read so far! – Henri Menke Nov 19 '13 at 23:22
I will add this to a set of standard answers. :D – Przemysław Scherwentke Nov 19 '13 at 23:39
+1 That's brilliant. – Jubobs Nov 19 '13 at 23:48
That's a nice answer! I didn't say please draw that for me, i only wanted some idea how to start and which concept of tikz (matrices,...) would be useful for such figures. So having the displayed figures is not helpful for me, since i need them with completely different content for my work. – wittmaan Nov 20 '13 at 7:15
@user2143654 My answer (which contained a hint of irony) is now obsolete since you changed your question. – Paul Gaborit Nov 20 '13 at 13:44