0

The flow chart below consists of blocks, representing data and functions, that run clockwise, while outside this series of blocks are explanatory steps. how would you code this in LaTeX while making the text both in the blocks and the surrounding steps editable? is Tikz the way to go? For use as a figure in a research article.

enter image description here

  • 2
    Please do not expect others to punch in all the texts from a screen shot. Please show us what you have tried. –  Apr 25 '20 at 05:03
  • to be honest, i'm completely new to tikz and have doubts it can even handle this challenge – develarist Apr 25 '20 at 05:04
  • 2
    It certainly can but probably not many want to punch in everything for you. –  Apr 25 '20 at 05:05
  • don't worry about punching everything. the placement of boxes, arrows, dots and the surrounding texts is what im worried about – develarist Apr 25 '20 at 05:06
  • I guess no one worries about a lot of text from screenshot. Without MWE showing what you have tried so far, simply you get low chance to be helped. – Black Mild Apr 25 '20 at 05:19
  • I do not know what you want to achieve by accepting an answer and unaccepting it considerable time later, but I can assure you that I am not excited about such games. –  Apr 26 '20 at 19:51

1 Answers1

7

The layout is easy, punching in texts is cumbersome. So I added a lot of bla bla. You only need matrices and some styles for hatching etc. To add the surrounding texts, put the diagram in a local bounding box and use the vertical or horizontal positions of the nodes for the placement of the texts.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,matrix,patterns.meta,positioning}
\begin{document}
\begin{tikzpicture}[node font=\sffamily,>=Triangle,
    Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
    line width=1.2pt,
    dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
    shorten >=0.5em,shorten <=0.5em},
    Dotted/.default=6,
    mmat/.style={matrix of nodes,nodes in empty cells,
        row sep=-\pgflinewidth,nodes={minimum width=3em,
            draw,anchor=center,
            text depth=0.25ex,text height=0.8em}},
    dotcell/.style={minimum height=4em,path picture={
        \draw[Dotted] (path picture bounding box.north)--
        (path picture bounding box.south);}},
    hatchcell/.style={pattern={Lines[angle=45,distance={3pt}]}},
    vcell/.style={xshift=-1ex,hatchcell},
    block/.style={draw,align=center}    
    ]
 \begin{scope}[local bounding box=diagram]
  \node[mmat] (vmat1) {|[vcell]|1 \\
     2 \\ |[dotcell]|\\  10\\ }; 
  %
  \node[mmat,below=2em of vmat1] (vmat2) {1 \\
     |[vcell]| 2 \\ |[dotcell]|\\  10\\ };   
  %
  \node[mmat,below=3em of vmat2] (vmat3) {1 \\
     2 \\ |[dotcell]|\\  |[vcell]|  10\\ };  
  %  
  \foreach \X in {1,2,3}
  {\node[right=3em of vmat\X,block](b\X){regression\textsubscript{a}\\
     regression\textsubscript{b}\\ regression\textsubscript{c}};
  \draw[->] (vmat\X-3-1.east|-b\X) -- (b\X);}
  %
  \node[right=3em of b1.south east,anchor=south west,mmat,
     column 1/.style={nodes={hatchcell}}] (hmat1) {
   1 & $Z_{1\mathsf{a}}$ & $Z_{1\mathsf{b}}$ & $Z_{1\mathsf{c}}$ \\
   2 & $Z_{2\mathsf{a}}$ & $Z_{2\mathsf{b}}$ & $Z_{2\mathsf{c}}$ \\
  }; 
  \draw[->] (b1.east|-hmat1-1-1.west) -- (hmat1-1-1.west);
  %
  \node[right=3em of b2.north east,anchor=north west,mmat,
     column 1/.style={nodes={hatchcell}}] (hmat2) {
   10 & $Z_{10\mathsf{a}}$ & $Z_{10\mathsf{b}}$ & $Z_{10\mathsf{c}}$ \\
  }; 
  \foreach \X [count=\Y] in {a,b,c}
  {\node[below=\Y*2em of hmat2-1-\the\numexpr\Y+1\relax,block] 
     (CV\Y) {CV Risk\textsubscript{\X}};
  \draw[->] (hmat2-1-\the\numexpr\Y+1\relax) -- (CV\Y); }
  \draw (CV1.west) -- ++ (-1ex,0) |- (CV3);
  \draw[->] (b2.east) -- ++(1em,0) |- (hmat1-2-1.west);
  \draw[->] (b3.east) -- ++(2em,0) |- (hmat2-1-1.west);
  %
  \node[block,below=12em of hmat2](F){Family of weighted\\
     combinations}; 
  \draw[->] (CV2.south-|F) -- (F);
  %
  \node[block,below=4em of F.south west,xshift=-3em] (P)
  {Some long formula with P}; 
  \draw[<-] (P.east) -- ++ (1em,0) coordinate (aux) -- (F.south-|aux);
  \node[block,left=3em of P,text width=8em] (PP)  {\vphantom{P}}; 
  \draw[->] (P) -- (PP);
  %
  \node[left=3em of vmat2.north west,block] (A){Collection of\\ algorithms}; 
  \node[left=3em of vmat2.south west,block] (MD){Mortality\\ data};  
  \draw[->] (A.east) -- ++ (1.2em,0) |- (vmat1-3-1);
  \draw[->] (A.east) -- ++ (1.2em,0) |- (vmat3-3-1);
  \draw[->] (MD.east) -- ++ (1.2em,0) |- (vmat2-3-1);
  \path (current bounding box.south west) + (-1ex,-1ex)
  (current bounding box.north east) + (1ex,1ex);
 \end{scope} 
 \node[text width=7em,above] at (MD|-diagram.north){1.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=7em,above] at (vmat1|-diagram.north){2.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=7em,above] at (b1|-diagram.north){3.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=12em,above] at (hmat1|-diagram.north){4.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=8em,right] at (hmat2-|diagram.east){5.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=8em,right] at (F-|diagram.east){6.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=9em,below] at (P|-diagram.south){7.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=9em,below] at (PP|-diagram.south){8.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
\end{tikzpicture}
\end{document}

enter image description here

This is a version that works on (some of the) outdated TeX installations.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,matrix,patterns,positioning}
\begin{document}
\begin{tikzpicture}[node font=\sffamily,>=Triangle,
    Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
    line width=1.2pt,
    dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
    shorten >=0.5em,shorten <=0.5em},
    Dotted/.default=6,
    mmat/.style={matrix of nodes,nodes in empty cells,
        row sep=-\pgflinewidth,nodes={minimum width=3em,
            draw,anchor=center,
            text depth=0.25ex,text height=0.8em}},
    dotcell/.style={minimum height=4em,path picture={
        \draw[Dotted] (path picture bounding box.north)--
        (path picture bounding box.south);}},
    hatchcell/.style={pattern=north east lines},
    vcell/.style={xshift=-1ex,hatchcell},
    block/.style={draw,align=center}    
    ]
 \begin{scope}[local bounding box=diagram]
  \node[mmat] (vmat1) {|[vcell]|1 \\
     2 \\ |[dotcell]|\\  10\\ }; 
  %
  \node[mmat,below=2em of vmat1] (vmat2) {1 \\
     |[vcell]| 2 \\ |[dotcell]|\\  10\\ };   
  %
  \node[mmat,below=3em of vmat2] (vmat3) {1 \\
     2 \\ |[dotcell]|\\  |[vcell]|  10\\ };  
  %  
  \foreach \X in {1,2,3}
  {\node[right=3em of vmat\X,block](b\X){regression\textsubscript{a}\\
     regression\textsubscript{b}\\ regression\textsubscript{c}};
  \draw[->] (vmat\X-3-1.east|-b\X) -- (b\X);}
  %
  \node[right=3em of b1.south east,anchor=south west,mmat,
     column 1/.style={nodes={hatchcell}}] (hmat1) {
   1 & $Z_{1\mathsf{a}}$ & $Z_{1\mathsf{b}}$ & $Z_{1\mathsf{c}}$ \\
   2 & $Z_{2\mathsf{a}}$ & $Z_{2\mathsf{b}}$ & $Z_{2\mathsf{c}}$ \\
  }; 
  \draw[->] (b1.east|-hmat1-1-1.west) -- (hmat1-1-1.west);
  %
  \node[right=3em of b2.north east,anchor=north west,mmat,
     column 1/.style={nodes={hatchcell}}] (hmat2) {
   10 & $Z_{10\mathsf{a}}$ & $Z_{10\mathsf{b}}$ & $Z_{10\mathsf{c}}$ \\
  }; 
  \foreach \X [count=\Y] in {a,b,c}
  {\node[below=\Y*2em of hmat2-1-\the\numexpr\Y+1\relax,block] 
     (CV\Y) {CV Risk\textsubscript{\X}};
  \draw[->] (hmat2-1-\the\numexpr\Y+1\relax) -- (CV\Y); }
  \draw (CV1.west) -- ++ (-1ex,0) |- (CV3);
  \draw[->] (b2.east) -- ++(1em,0) |- (hmat1-2-1.west);
  \draw[->] (b3.east) -- ++(2em,0) |- (hmat2-1-1.west);
  %
  \node[block,below=12em of hmat2](F){Family of weighted\\
     combinations}; 
  \draw[->] (CV2.south-|F) -- (F);
  %
  \node[block,below=4em of F.south west,xshift=-3em] (P)
  {Some long formula with P}; 
  \draw[<-] (P.east) -- ++ (1em,0) coordinate (aux) -- (F.south-|aux);
  \node[block,left=3em of P,text width=8em] (PP)  {\vphantom{P}}; 
  \draw[->] (P) -- (PP);
  %
  \node[left=3em of vmat2.north west,block] (A){Collection of\\ algorithms}; 
  \node[left=3em of vmat2.south west,block] (MD){Mortality\\ data};  
  \draw[->] (A.east) -- ++ (1.2em,0) |- (vmat1-3-1);
  \draw[->] (A.east) -- ++ (1.2em,0) |- (vmat3-3-1);
  \draw[->] (MD.east) -- ++ (1.2em,0) |- (vmat2-3-1);
  \path (current bounding box.south west) + (-1ex,-1ex)
  (current bounding box.north east) + (1ex,1ex);
 \end{scope} 
 \node[text width=7em,above] at (MD|-diagram.north){1.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=7em,above] at (vmat1|-diagram.north){2.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=7em,above] at (b1|-diagram.north){3.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=12em,above] at (hmat1|-diagram.north){4.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=8em,right] at (hmat2-|diagram.east){5.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=8em,right] at (F-|diagram.east){6.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=9em,below] at (P|-diagram.south){7.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
 \node[text width=9em,below] at (PP|-diagram.south){8.\ bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla
 bla bla};
\end{tikzpicture}
\end{document}
  • the code runs into several errors when compiling: Package pgf Error: Undefined pattern `Lines'. \node[mmat] (vmat1) {|[vcell]|1 \ – develarist Apr 26 '20 at 19:52
  • 1
    @develarist That's because you have an old TeX installation. patterns.meta has been added only recently. If you cannot update, load patterns instead of patterns.meta and use hatchcell/.style={pattern={north east lines}}. –  Apr 26 '20 at 20:01
  • i was thinking that and updated everything in the miktex console on my first attempt. there were other errors after this though – develarist Apr 26 '20 at 20:03
  • @develarist Sorry, this code compiles fine, at least on an updated TeXLive 2020 installation. I do not have a crystal ball that would tell me what goes wrong, so if you say "there were other errors" this does not help. –  Apr 26 '20 at 20:04
  • i will let u know when this patterns error is fixed. i see the other errors when I comment out the sources of the patterns error. tikz is updated, and i know that "Lines" is within patterns.meta after consulting similar questions before I complained here, but it says the error is in the package called pgf. – develarist Apr 26 '20 at 20:24
  • @develarist Your messages are not helpful, sorry. One can only fix errors (which, I stress again, this code does not produce on a reasonably up-to-date installation) only if one sees the precise error messages. –  Apr 26 '20 at 20:30
  • Package pgf Error: Undefined pattern `Lines'. \node[mmat] (vmat1) {|[vcell]|1 \ .... Package pgf Error: No shape named MD is known. ...xt width=7em,above] at (MD|-diagram.north) ... – develarist Apr 26 '20 at 20:31
  • 1
    @develarist I see. You told me that you have fixed the patterns.meta related errors but you did not. I added a version that works without patterns.meta. –  Apr 26 '20 at 20:43
  • works now. thanks alot – develarist Apr 26 '20 at 20:44
  • Inside this \foreach \X in {1,2,3} {\node[right=3em of vmat\X,block](b\X){regression\textsubscript{a}\\ regression\textsubscript{b}\\ regression\textsubscript{c}}; \draw[->] (vmat\X-3-1.east|-b\X) -- (b\X);} there appears this expression: (vmat\X-3-1.east|-b\X) -- (b\X) which after the loop would be written as: (vmat1-3-1.east|-b1) -- (b1) and so on... Does anybody know what the -3-1 before the anchor mean? Also what does the | symbol do? – Michel Jan 17 '23 at 09:47