1

I'm trying to recreate the following block diagram with Tikz.

I created the block diagram with the following code:

\tikzstyle{node}=[draw, fill=pink, minimum width=4.2cm]
\tikzstyle{init} = [pin edge={to-,thin,black}]
\tikzstyle{end} = [pin edge={-to,thin,black}]

\begin{figure}
\begin{tikzpicture}[node distance=0.35cm, auto,>=latex']
    \node [node, align=center, pin={[init, align=center, pin distance=0.35cm]above:{\footnotesize data}}] (a) {\small a};
    \node [node, align=center, below= of a] (b) {\small b};
    \node [node, align=center, below= of b] (c) {\small c};
    \node [node, align=center, below= of c] (d) {\small d};
    \node [node, align=center, below= of d] (e) {\small e};
    \node [node, align=center, below= of e] (f) {\small f};
    \node [node, align=center, below= of f, pin={[end, align=center, pin distance=0.35cm]below:{\footnotesize data}}]  (g) {g};
    \path[->] (a) edge (b);
    \path[->] (b) edge (c);
    \path[->] (c) edge (d);
    \path[->] (d) edge (e);
    \path[->] (e) edge (f);
    \path[->] (f) edge (g);
\end{tikzpicture}
\caption{Block diagram.}
\label{fig:diagram}
\end{figure}

Resulting in this:

enter image description here

However, I wanted to draw a few arrows with a description next to the nodes but have no idea how to accomplish this. The idea was to look something like this:

enter image description here

How can I do something like this? Thank you so much.

| improve this question | | | | |
  • 1
    Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code. – Andrew Mar 5 at 12:12
3

Perhaps something like this:

enter image description here

I have rationalised the code in the OP a little by using \foreach loops. If the contents of the nodes is more exciting than a,...,g then you can use the same trick that I used with the descriptions to add this extra information to the \foreach loop.

To add the descriptions I have used the eastern boundaries of the "pink" nodes together with a small xshift=4mm and a node for the descriptive text. The only other change is to use \tikzset instead of the now depreciated `\tikzstyle.

Here is the updated code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta}
\begin{document}

\tikzset{
  node/.style={draw, fill=pink, minimum width=4.2cm},
  data/.style={align=center, minimum width=4.2cm}
}

\begin{tikzpicture}[node distance=0.35cm, auto,>=latex]
  \node[data](data) {\footnotesize data};
    \foreach \nd [remember=\nd as \Nd (initially data)] in {a,...,g} {
        \node [node, align=center, below=of \Nd] (\nd) {\small \nd};
        \draw[->](\Nd)--(\nd);
    }
    \node[data, below=of g] (Data) {\footnotesize data};
    \draw[->](g)--(Data);
    \foreach \nd/\desc [remember=\nd as \Nd (initially data)]
        in {a/description 1,c/description 2,e/description 3,g/description 4, Data/description 5} {
      \draw[blue, <->]([xshift=4mm]\Nd.east)--node[right]{\desc}([xshift=4mm]\nd.east);
    }
\end{tikzpicture}

\end{document}

Edit

Following Thomas' answer to How to add newline within node using TikZ?, if you want to have multi-line descriptions then it is enough to add alignment to the description nodes. I have done this by adding an extra desc style to produce:

enter image description here

Here is the updated code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta}
\begin{document}

\tikzset{
  node/.style={draw, fill=pink, minimum width=4.2cm},
  data/.style={align=center, minimum width=4.2cm},
  desc/.style={align=left, right}
}

\begin{tikzpicture}[node distance=0.35cm, auto,>=latex]
  \node[data](data) {\footnotesize data};
    \foreach \nd [remember=\nd as \Nd (initially data)] in {a,...,g} {
        \node [node, align=center, below=of \Nd] (\nd) {\small \nd};
        \draw[->](\Nd)--(\nd);
    }
    \node[data, below=of g] (Data) {\footnotesize data};
    \draw[->](g)--(Data);
    \foreach \nd/\desc [remember=\nd as \Nd (initially data)]
        in {a/description 1,c/description 2,e/description 3,g/description 4\\that is a little longer, Data/description 5} {
      \draw[blue, <->]([xshift=4mm]\Nd.east)--node[desc]{\desc}([xshift=4mm]\nd.east);
    }
\end{tikzpicture}

\end{document}
| improve this answer | | | | |
  • This is exactly what I was looking for, thank you much! I've got a lot to learn :) any tips for improving, such as tutorials? – Hel Mar 5 at 14:17
  • How can I break the lines in the descriptions? I've tried adding like this: {description // 1} I get a missing item error... – Hel Mar 5 at 14:27
  • @Hel, regarding line breaks in descriptions see my answer :-) – Zarko Mar 5 at 15:35
  • @Hel See my edit – Andrew Mar 5 at 21:00
1

Small (off-topic) variation of nice @Abdrew answer:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                chains,       % new
                positioning,
                quotes         % new
                }

\begin{document}
    \begin{tikzpicture}[auto,
node distance = 4mm and 3mm,
            > = {Triangle[angle=45:1pt 3]},
  start chain = A going below,
  base/.style = {text width=42mm, align=center, font=\small,
                 on chain=A, join=by -Straight Barb},
   box/.style = {base, draw, fill=pink},
every edge quotes/.style = {align=left, font=\scriptsize}
                        ]
% nodes in chain
\node [base,font=\footnotesize]    {data};
\foreach \i in {a,...,g}
{
\node [box] {\i};
}
\node [base,font=\footnotesize]    {data};
% arrows
\def\dscr{2/Description 1,
          4/Description 2 \\ has two lines,
          6/Description 3,
          8/Description 4,
          9/Description 5}
\foreach \i/\j [remember=\i as \k (initially 1)] in \dscr
{
\draw[blue,<->, semithick] ([xshift=4mm] A-\k.east) edge ["\j"] ([xshift=4mm] A-\i.east);
}    \end{tikzpicture}
\end{document}

enter image description here

Note: in the case, that the real content of nodes in chain have longer description you can similarly as is done for arrows labels define list of nodes contents and read its contains in \forach loop:

% ...
\node [base,font=\footnotesize]    {data};
\def\task{first task,
          description of the second task has,
          task c,
          after task c\\ follows task d,
          e,
          f,
          g}
\foreach \i in \task
{
\node [box] {\i};
}
% ...

which gives:

enter image description here

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.