2

I'm a LaTeX beginner and I'm struggling with creating a flow chart. I have the following code so far:

\documentclass[final, english]{scrreprt}

\usepackage{tikz,pgfplots}
    \pgfplotsset{compat=newest}
\usetikzlibrary{arrows,trees,graphs,positioning, arrows, chains, shapes, arrows.meta,decorations.pathreplacing}
\usepackage{pstricks,pst-node,pstricks-add}

\begin{document}

\begin{figure}
\centering

\begin{tikzpicture}[node distance=1.5cm]

    \tikzstyle{process1} = [rectangle, minimum width=11cm, minimum height=1cm, text centered, draw=black] 
    \tikzstyle{process2} = [rectangle, minimum width=6cm, minimum height=1cm, text centered, draw=black] 
    \tikzstyle{decision} = [diamond, base, minimum width=5cm, minimum height=1cm, text centered, draw=black, aspect=2, inner xsep=0mm]
    \tikzstyle{stop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black]
    \tikzstyle{arrow} = [thick,->,>=stealth]
    
    %Nodes erstellen
    \node (start) [process1] {\begin{tabular}{c}
        Box 1: Row 1 \\
        Row 2
    \end{tabular}};    
    
    %Process boxes
    \node (p2) [process1, below of=start, yshift = -0.2cm] {Box 2};
    \node (p3) [process1, below of=p2] {Box 3};
    \node (p4) [process1, below of=p3] {Box 4};
    \node (p5) [process1, below of=p4] {Box 5};

    %decision boxes
    \node (dec1) [decision, below left of=p5, yshift=-1.5cm] {\begin{tabular}{c}
        Decision Box 1: Row 1 \\
        Row 2 \\
        Row 3 \\
        Row 4
    \end{tabular}};     
    \node (dec2) [decision, below right of=dec1, yshift=-4cm] {\begin{tabular}{c}
        Decision Box 2: Row 1 \\
        Row 2 \\
        Row 3 \\
        Row 4
    \end{tabular}};       
    
    %small process boxes
    \node (p6) [process2, below left of=dec1, yshift=-2cm] {\begin{tabular}{c}
        Box 6: Row 1 \\
        Row 2 \\
        Row 3 
    \end{tabular}};   
    
    \node (p7) [process2, below of=dec2, yshift=-2cm] {\begin{tabular}{c}
        Box 7: Row 1 \\
        Row 2 \\
        Row 3 
    \end{tabular}};    
    
    \node (p7) [process2, below of=dec2] {\begin{tabular}{c}
        Box 7: row 1\\
        row 2
    \end{tabular}};
    
    \node (dec3) [decision, below of=p6, yshift=-2cm] {Decision box};
    
    \node (p8) [process2, below of=p7] {\begin{tabular}{c}
        Box 7: row 1\\
        row 2
    \end{tabular}};

    \node (dec4) [decision, below right of=dec3, yshift=-2cm] {\begin{tabular}{c}
        Last decision box \\
        another row
    \end{tabular}};    
    
    \node (stop) [stop, right of=dec4] {STOP};
    
    % arrows
    \draw [arrow] (start) -- (p2);
    \draw [arrow] (p2) -- (p3);
    \draw [arrow] (p3) -- (p4);
    \draw [arrow] (p4) -- (p5);    
    
    % Labeled arrows
    \draw [arrow] (dec1) -- node {Yes} (p6);
    \draw [arrow] (dec1) -- node {No} (dec2);
    
    \draw [arrow] (dec2) -- node {Yes} (p7);
    \draw [arrow] (dec2) -- node {No} (p8);
    
    \draw [arrow] (dec3) -- node {Yes} (dec1);
    \draw [arrow] (dec3) -- node {No} (dec4);
    
    \draw [arrow] (dec4) -- node {Yes} (stop);
    \draw [arrow] (dec4) -- node {No} (p4);
    
\end{tikzpicture}
\end{figure}

\end{document}

I am currently failing because the decision boxes are diagonally next to each other. In the end, the flow chart should look as similar as possible to the template and accordingly I also have to manage the alignment so that it is formatted in the same way.

  1. How do I get decision boxes 1 and 2 aligned diagonally next to each other?
  2. What trick is there so that the arrows make angular curves at certain points and do not end directly in a box, but in other arrows?
  3. is there a better way to create a line break within the boxes than to make a tabular environment?

I would like to thank everyone who can help me!

2
  • 1
    Welcome to TeX.SE!
    – Mensch
    May 28, 2021 at 9:34
  • 1. Those boxes are not strictly aligned one to another. You can do it by try and error. 2. Something like \draw[->] (node1) |-([yshift=5pt] node2.north) would work. 3. Add text width into your node declaration, which allocates a specific width to the text and force line breaks.
    – SebGlav
    May 28, 2021 at 12:51

2 Answers 2

3

Just to let you see the idea of what I said in my comment. This is not the best way to do that, but at least, it's customizable and easy to understand. The first boxes could (should?) be done using chain, which requires less code. Anyway:

flowchart

\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}

\tikzset{
    process1/.style={rectangle, minimum width=11cm, minimum height=1cm, text width=10cm,text centered, draw=black},
    process2/.style={rectangle, minimum width=6cm, minimum height=1cm, text width=5cm,text centered, draw=black},
    decision/.style={diamond, text centered, draw=black, aspect=2, inner xsep=-2mm},
    stop/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black},
    arr/.style={thick,-stealth}
    }
\begin{document}
    \begin{tikzpicture}[node distance=1cm]
        \node[process1] (start) {Initiate the seed permutation sequence by a proven scheduling heuristic: Set of scheduled jobs $=\lbrace\delta\rbrace$};
        \node[below = of start,process1] (box2) {Pick the first job that occurs in $\lbrace\delta\rbrace$};
        \node[below = of box2,process1] (box3) {Whatever text you want to put here};
        \node[below = of box3,process1] (box4) {Whatever text you want to put here};
        \node[below = of box4,process1] (box5) {Whatever text you want to put here};
        
        \node[below left =2cm and -3cm of box5,decision,text width=4cm] (dec1) {On the following machine stage, can job be inserted completely ahead of preceding job in $\lbrace\delta\rbrace$};
        \node[below right = 1cm and 2cm of dec1,decision,text width=4cm] (dec2) {Is insertion including job shifting of precding jobs in $\lbrace\delta\rbrace$ possible?};
        
        \node[below left = 2cm and -3cm of dec1,process2] (p6) {Implement insertion of job, compute its ST and FT on machine \textit{i}, reschedule jobs in $\lbrace\delta\rbrace$ which are affected by insertion on machine \textit{i}};
        
        \node[below = 4cm of  p6,decision] (p7) {$i< m$?};
        
        \draw[arr] (start) -- (box2);
        \draw[arr] (box2) -- (box3);
        \draw[arr] (box3) -- (box4);
        \draw[arr] (box4) -- (box5);
        \draw[arr] (box5.south) --++ (0,-10pt) -| (dec1);
        \draw[arr] (dec1) -| (dec2) node[pos=0.1,above]{\textit{No}};
        \draw[arr] (dec1.south) --++ (0,-10pt) -| (p6) node[pos=0.3,above]{\textit{Yes}};
        \draw[arr] (p6) -- (p7);
        \draw[arr] (dec2) |- ([yshift=20pt]p7.north);
    \end{tikzpicture}
\end{document}
2

A bit different design, in flowchart code is employed the chains library:

\documentclass[final, english]{scrreprt}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains, 
                positioning, 
                quotes,
                shapes.symbols}
\makeatletter
\tikzset{FlowChart/.style={
suppress join/.code={\def\tikz@after@path{}},
    off chain/.code={\def\tikz@lib@on@chain{}},
%
node distance = 7mm and 5mm,
  start chain = going below,
%
   arr/.style = {thick,-Stealth},
  base/.style = {draw, semithick, minimum height=3ex, align=center}, 
proces/.style = {base, text width=##1},
proces/.default = 24em,
decision/.style = {signal, signal pointer angle=120,
                   signal to=west and east, 
                   base, text width=##1, inner xsep=0ex},
decision/.default = 8em,
  stop/.style = {rounded corners, fill=gray!10, minimum width=12ex},
                            }
        }
\makeatother

\begin{document}
    \begin{figure}
\centering
    \begin{tikzpicture}[FlowChart]
%   Nodes erstellen
    \begin{scope}[nodes={on chain, join=by arr}]
\node (s)   [proces]    {Initiate the seed permutation sequence by a proven scheduling heuristic: Set of scheduled jobs $=\{\delta\}$};
%   Process boxes
\node (p2) [proces]     {Box 2};
\node (p3) [proces]     {Box 3};
\node (p4) [proces]     {Box 4};
\coordinate (aux0);
\node (p5) [proces]     {Box 5};
\coordinate (aux1);
%   decision boxes
\node (d1) [decision=12em]   
                        {On the following machine stage, can job be inserted completely ahead of preceding job in $\{\delta\}$};
%   left branch
\node (p6)  [proces=9em, 
off chain, suppress join,
             below left=of d1]   {Implement insertion of job, compute its ST and FT on machine $i$, reschedule jobs in $\{\delta\}$ which are affected by insertion on machine $i$};
\coordinate [below=of p6]   (aux2);
\node (d2)  [decision, 
             below=14mm of aux2]   {$i\leq m$ ?};
\node (d3)  [decision]   {Are al jobs in $\{\delta\}$ considered};
    \end{scope}
%   right branch
\node (d4)  [decision=9em, 
             below right=of d1] {Is insertion including job shifting of precding jobs in $\{\delta\}$ possible?};
\node (p7)  [proces=12em,
             below left=of d4]       {Implement insertion of job, compute its ST and FT on machine $i$, reschedule jobs in $\{\delta\}$ an machine $i$ to $m$ and check further possible job swaps};
\node (p8)  [proces=8em,
             below=of d4]  {Compute ST and FT of this job on machine $i$};
% end flowchart
\node (s)   [stop,
             right=of d3 -| p7] {STOP};
%   connection not included in join macro
    \draw[arr] (d1.west) node[above left]   {Yes} -|  (p6); 
    \draw[arr] (d1.east) node[above right]  {No} -|  (d4);
    
    \draw[arr] (d2.west) node[above left]   {Yes} -|  ([xshift=-2.2em] p6.west) |- (aux1);
    \draw[arr] (d3.west) node[above left]   {No}  -|  ([xshift=-3em] p6.west) |- (aux0);

    \draw[arr] (d4.west) node[above left]   {Yes} -| (p7);
    \draw[arr] (d4.south) -- node[right]    {No}  (p8)
               (p7.west |- aux2) -- (aux2); 
    \draw[arr] (p8) |- (d2);
    \draw[arr] (d3.east) node[above right]  {Yes}  -- (s);
    \end{tikzpicture}
    \end{figure}
\end{document}

enter image description here

(red lines indicate page layout)

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.