8

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

enter image description here

enter image description here

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?

8
  • 3
    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, 2013 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.
    – jub0bs
    Nov 19, 2013 at 21:02
  • 1
    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? Nov 20, 2013 at 10:37
  • 1
    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]) Nov 21, 2013 at 21:17
  • 1
    @wittmaan It seems that your images are no longer visible.
    – Karlo
    May 2, 2016 at 12:13

2 Answers 2

14

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 the ext.node-families library from the linked question/answer.

The second problem, better connections between the matrices I am going to use the keys only horizontal first and only vertical first from the ext.paths.ortho library which got developed for another Antwort von mir.
These are similar to the path operations -| and |- but don't draw the second part. An optional argument shifts the resulting line orthogonally to its direction.

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 (“Longer Text D” and “Text E”), 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).

The ext.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.


All mentioned libraries starting with ext. are part of my tikz-ext package.

Code

\documentclass[tikz,border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{
  arrows.meta,          % for proper arrows
  matrix,               % for “matrix of nodes”
  ext.positioning-plus, % for “x/y_node_dist”, “north right=of …”
  ext.node-families,    % for “node family/width”
  ext.paths.ortho       % for “only vertical first”
}
\tikzset{
  fitty line width/.initial=.25cm,
  fitty/.style={
    fit=(#1')(#1''),
    line width=\pgfkeysvalueof{/tikz/fitty line width},
    inner sep=\pgfkeysvalueof{/tikz/fitty line width}/2,
    draw, name=#1},
}
\begin{document}
\begin{tikzpicture}[
  my matrix*/.style={
    nodes={inner sep=+1em, typetag, node family/width=m, text depth=+0pt},
    matrix of nodes, row sep=+.5em, node family/width=M},
  my matrix/.style={
    my matrix*, draw, row 1/.append style={nodes=title}},
  title/.style={draw=none, node font=\bfseries},
  Title/.default=-+, % use different signs for different placements
  Title/.style 2 args={
    title, draw, node family/width=M,
    fill, text=white, text depth=+0pt, inner ysep=.5em, outer sep=+0pt,
    yshift=(\pgfkeysvalueof{/tikz/fitty line width})*#11,
    xshift=(\pgfkeysvalueof{/tikz/fitty line width})*#21},
  typetag/.style={draw=black, inner sep=1ex, align=center},
  >=Latex
]

  \matrix[my matrix] (mx1) {
    Text A \\
    Text 1 \\
    Text 2 \\
    Text 3 \\
    Text 4 \\
    Text 5 \\
    Text 6 \\
  };
  
  % Title makes sure the extra thick line around everything is taken
  % into account, i.e. the node needs to be shifted a bit more
  \node[Title, north right=of mx1]       (mx2')  {Longer Text D};
  \matrix[my matrix, below=+0pt of mx2'] (mx2'') {
    Text ABC\\
    Text 13 \\
    Text 14 \\
    Text 15 \\
    Text 16 \\
    Text 17 \\
    Text 18 \\
  };
  \node[fitty=mx2]{}; % the thick black box around it

  \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, xshift=-.5*x_node_dist] (mx5) {
    Text B  \\
    Text 7  \\
    Text 8  \\
    Text 9  \\
    Text 10 \\
    Text 11 \\
  };
  \matrix[my matrix, north right=of mx5] (mx4) {
    Text C  \\
    Text 12 \\
  };

  \path [thick, ->]
    [only horizontal first=-y_node_dist] 
      (mx1.north east) edge (mx2)
      (mx3.north west) edge (mx2)
    (mx5.south east) edge[only vertical first=-x_node_dist] (mx2)
    (mx4.south west) edge[only vertical first= x_node_dist] (mx2);
\end{tikzpicture}
\end{document}

Output

enter image description here

1
  • 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, 2013 at 12:02
13

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}
5
  • 6
    +1 This is the best answer on "Please, draw it for me" questions I've read so far! Nov 19, 2013 at 23:22
  • I will add this to a set of standard answers. :D Nov 19, 2013 at 23:39
  • 3
    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, 2013 at 7:15
  • 1
    @user2143654 My answer (which contained a hint of irony) is now obsolete since you changed your question. Nov 20, 2013 at 13:44
  • A deprecated answer can still get voted up. Nov 24, 2013 at 0:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .