2

I'm trying to draw a flow diagram using TikZ.

I would like that the wording in the arrows appeared either left or right of the path, instead of on top of the arrows. I also tried to work around this using node opacity and style={fill=white} but it didn't work.

Also I managed to position the nodes the way I intended to, but I'm sure there are many easier ways to do this. I saw stuff like the matrix library and layered layouts, but couldn't implement it successfully.

Lastly, I would like to have an arrow like the one I drew manually in the picture. I tried using controls, but the results are not quite what I intended because the arrow crosses some nodes.

Thank you very much for your support.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\scalebox{0.6}[0.6]{
    \begin{tikzpicture}
        [>=stealth, place/.style={shape=rectangle,draw,rounded corners,fill=blue!25,},trans/.style={align=center},auto,scale=3]         
        \node[place] (a1) {Input};
        \node[trans,right=2cm of a1] (b1) {Replicate};
        \node[place,right=2.05cm of b1] (c1) {Working};
        \node[below=0.5cm of b1 ,shape=rectangle,draw,rounded corners,fill=red!25,inner sep=4] (a2) {\LARGE \centering Imputation Step Iteration 1};
        \node[place,below=1.75cm of a1] (a3) {Input};
        \node[place,below=1.75cm of c1] (b3) {Working};
        \node[trans,below=0.6cm of a3] (a4) {\footnotesize SSCPMISS};   
        \node[trans,below=0.5cm of b3,] (b4) {Replicate};
        \node[shape=rectangle,draw,rounded corners,fill=blue!25,align=center,below=0.6cm of a4] (a5) {SSCP};
        \node[rectangle,draw,rounded corners,fill=green!25,inner sep=8, right=0.6cm of a5] (b5) {\Large Imputation: 1\textsuperscript{st} row};
        \node[place,below=0.55cm of b4,] (c5) {Output};
        \node[place, below=0.5cm of b5] (a6) {Output};
        \node[trans, below=0.5cm of a6] (a7) {Copy imputed values for every row};
        \node[place, below=0.5cm of a7] (a8) {Output};
        \node[rectangle,draw,rounded corners,fill=green!25,inner sep=8, below=0.5cm of a8] (a9) {\Large Imputation: PXXXX\_O};
        \node[place, below=0.5cm of a9] (c10) {Output};
        \node[trans, left=0.5cm of c10] (b10) {Output N \\=\\ Input N+1};
        \node[place, left=0.5cm of b10] (a10) {Input};
        \node[trans, right=0.5cm of c10] (d10) {Save \\ iteration\\  output};
        \node[place, right=0.8cm of d10] (e10) {Output\_1};
        \node[below=1cm of c10 ,shape=rectangle,draw,rounded corners,fill=red!25,inner sep=4] (a11) {\LARGE \centering Imputation Step Iteration 2};
        \node[place,below=13cm of c1] (b12) {Working};
        \node[place,below=13cm of a1] (a12) {Input};    
        %  
        \draw [->,] (a1) -- (c1);
        \draw [->,] (a1) -- (a2);
        \draw [->,] (c1) -- (a2);
        \draw [->,] (a3) -- (a5);
        \draw [->,] (b3) -- (c5);
        \draw [->,] (a5) -- (b5);
        \draw [->,] (c5) -- (b5);
        \draw [->,] (b5) -- (a6);
        \draw [->,] (a6) -- (a8);
        \draw [->,] (a8) -- (a9);
        \draw [->,] (a9) -- (c10);  
        \draw [->,] (c10) -- (a10);
        \draw [->,] (c10) -- (e10);
        \draw [->,] (a10) |- (a11);
    \end{tikzpicture}
}
\end{document}

enter image description here

  • 2
    For the node in midway of the arrows, you can use midway. For the curved arrow, there are many options: controls, to, plot coordinates, etc. – user156344 Feb 27 '19 at 15:44
  • Thank you for both comments. midway worked nicely to bypass the text on top of arrow problem. About starting with the a2 node: I din't just because I needed to show that Input and working are basically the same on iteration 1. – Luís Martins Feb 27 '19 at 15:52
  • Is it possible to add the node e10 as control for the arrow I want? If so, could you please show me? – Luís Martins Feb 27 '19 at 15:55
  • I'm going to bed now so I'm not gonna do that - but there are many others who can help you. Btw, for the arrows, I would not use controls, but to. – user156344 Feb 27 '19 at 16:02
1

using beamer document class should meaning that your image is in frame environment ... so i adopt your image to the size of the standard frame. also use library quotes for edge labeling:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning, quotes}

\begin{document}
\begin{frame}[fragile]
\frametitle{Work flow?}
    \begin{center}
    \begin{tikzpicture}[,
node distance = 4mm and 6mm,
   box/.style = {rectangle, draw, rounded corners,
                 fill=#1, font=\footnotesize, inner ysep=1.5pt},
 box/.default = blue!25,
every edge/.style = {draw, semithick,-Stealth},
every edge quotes/.style = {auto=left, align=center, inner sep=2pt,
                            font=\scriptsize\linespread{0.7}\selectfont}
                        ]
\node (a1) [box]    {Input};
\node (a2) [box=red!25, font=\small,
            below right=of a1]      {Imputation Step Iteration 1};
\node (a3) [box,above right=of a2]  {Working};
\node (a4) [box,below  left=of a2]  {Input};
\node (a5) [box,below right=of a2]  {Working};
\node (a6) [box,below=of a4]    {SSCP};
\node (a7) [box,below=of a5]    {Output};
    \path (a6) -- node (a8) [box=green!25,inner sep=4pt]
                            {Imputation: 1\textsuperscript{st} row} (a7);
\node (a9)  [box,below=of a8]   {Output};
\node (a10) [box,below=of a9]   {Output};
\node (a11) [box=green!25,inner sep=4pt,
             below=of a10]    {Imputation: PXXXX\_O};
%
\node (a12) [box,below  left=of a11]    {Input};
\node (a13) [box,below=of a11]          {Output};
\node (a14) [box,below right=of a11]    {Output\_1};
\node (a15) [box=red!25,inner sep=4,
             below=of a13] {Imputation Step Iteration 2};
%
\node (a16) [box,below  left=of a15]   {Input};
\node (a17) [box,below right=of a15]   {Working};
        %
\draw   (a1) edge ["Replicate"] (a3)
        (a1) edge (a2)
        (a3) edge (a2)
%
        (a4) edge ["SSCPMISS"]  (a6)
        (a5) edge ["Replicate"] (a7)
        (a6) edge (a8)
        (a7) edge (a8)
%
        (a8) edge (a9)
        (a9) edge ["Copy imputed values for every row"] (a10)
        (a10) edge (a11)
        (a11) edge (a13)
%
        (a13) edge ["Output N =" ',"Input N+1"] (a12)%\\=\\ };
        (a13) edge ["Save iteration\\ output"] (a14)
%
        (a3) edge [bend left=44] (a17)
        ;
\draw[-Stealth] (a12) |- (a15);
\draw[-Stealth] (a14) |- (a15);
    \end{tikzpicture}
    \end{center}
\end{frame}
\end{document}

enter image description here

in case that above image is still to big, you can scale ti down with adding to tikzpicture's options for example: scale=0.9, transform shape,

  • This is exactly what I was looking for. Thank you very much! – Luís Martins Feb 28 '19 at 7:16
3

Here is a starting point. I'll be happy to remove this. I would start with the bulky node in the upper middle and then draw things relative to this. And, as mentioned by Joule V, one can use midway to place the labels. (You were adding auto but did not give TikZ a chance to use it.)

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\scalebox{0.6}[0.6]{
    \begin{tikzpicture}[>=stealth, place/.style={shape=rectangle,draw,rounded corners,fill=blue!25,},trans/.style={align=center},auto,scale=3]         
        \node[place,fill=green!25,inner sep=8, font=\Large ] (b5) {Imputation: 1\textsuperscript{st} row};
        \node[left=0.4cm of b5,place]  (a5) {SSCP};
        \node[right=0.4cm of b5,place]  (c5) {Output};
        \node[above=1cm of a5,place]  (a3) {Input};
        \node[above=1cm of c5,place]  (b3) {Working};
        \node[place,above=2cm of b5,fill=red!25,inner sep=4,font=\LARGE,align=center] 
        (a2) {Imputation Step Iteration 1};
        \node[place,above=2cm of a3] (a1) {Input};
        \node[place,above=2cm of b3] (c1) {Working};
        \draw [->] (a1) -- (c1) node[midway,above] (b1) {Replicate};
        \draw [->] (a3) -- (a5) node[midway,left,font=\footnotesize] (a4) {SSCPMISS};
        \draw [->] (b3) -- (c5) node[midway,right,font=\footnotesize]  (b4) {Replicate};
        \node[place, below=0.5cm of b5] (a6) {Output};
        \node[place, below=1.5cm of a6] (a8) {Output};
        \draw [->] (a6) -- (a8) node[midway,right,text width=3.5cm]{Copy imputed values for every row};
        \node[place,fill=green!25,inner sep=8, below=0.5cm of a8,font=\Large] (a9) {Imputation: PXXXX\_O};
        \node[place, below=0.5cm of a9] (c10) {Output};
        \node[place, left=3cm of c10] (a10) {Input};
        \draw [->] (c10) -- (a10) node[midway,auto=false,trans]
            (b10) {Output N \\=\\ Input N+1};
        \node[place, right=3cm of c10] (e10) {Output\_1};
        \draw [->] (c10) -- (e10) node[midway,trans,auto=false] (d10) {Save \\ iteration\\  output};
        \node[below=1cm of c10 ,place,fill=red!25,inner sep=4,font=\LARGE ] (a11) {Imputation Step Iteration 2};
        \node[place,below=13cm of c1] (b12) {Working};
        \node[place,below=13cm of a1] (a12) {Input};    
        %  
        \draw [->] (a1) -- (a2);
        \draw [->] (c1) -- (a2);
        \draw [->] (a5) -- (b5);
        \draw [->] (c5) -- (b5);
        \draw [->] (b5) -- (a6);
        \draw [->] (a8) -- (a9);
        \draw [->] (a9) -- (c10);  
        \draw [->] (a10) |- (a11);
        %
        \draw[->] (c1) to[out=-45,in=30] (b12);
    \end{tikzpicture}
}
\end{document}

enter image description here

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.