3

I want to separate the flowchart into phases by adding the red items. Any idea how to do it?enter image description here

This is the code for my current flowchart.

\documentclass{article}
\usepackage{tikz,tkz-berge,tkz-graph}
\usetikzlibrary{graphs, graphs.standard, shapes.geometric, arrows, decorations.pathreplacing, positioning, quotes}

\begin{document}
\begin{figure}[htbp!]
\centering
\begin{tikzpicture}
    \tikzstyle{rectlong} = [draw,rectangle,fill=white!20,text width=10em,text centered,minimum height=1.75em]
    \tikzstyle{rectshort} = [draw,rectangle,fill=white!20,text width=5em,text centered,minimum height=1.75em]
    \tikzstyle{rectultralong} = [draw,rectangle,fill=white!20,text width=19.5em,text centered,minimum height=1.75em]
    \tikzstyle{rectmed} = [draw,rectangle,fill=white!20,text width=15em,text centered,minimum height=1.75em]
    \node[rectlong,rounded corners](A){\small User input};
    \node[rectlong,rounded corners,below left=0.75cm and 1.2cm of A](B){\small terrain map};
    \node[rectlong,rounded corners,below=0.5cm of B](E){\small vertex-weighted grid graph $G$};
    \node[rectshort,rounded corners,below=1.5cm of E](G){\small $c^2=\left[\ldots\right]$};
    \node[rectshort,rounded corners,left=0.5cm of G](F){\small $c^1=\left[\ldots\right]$};      
    \node[rectshort,rounded corners,right=0.5cm of G](H){\small $c^3=\left[\ldots\right]$};
    \node[rectshort,rounded corners,below=0.5cm of G](J){\small $\hat{c}^2=\left[\ldots\right]$};
    \node[rectshort,rounded corners,left=0.5cm of J](I){\small $\hat{c}^1=\left[\ldots\right]$};
    \node[rectshort,rounded corners,right=0.5cm of J](K){\small $\hat{c}^3=\left[\ldots\right]$};
    \node[rectshort,rounded corners,right=0.5cm of K](C){\small $\mathbf{w}=(w_1,w_2,w_3)$};
    \node[rectlong,rounded corners,below=1.2cm of K](L){\small grid graph with weighted sum cost $G'$};
    \node[rectshort,rounded corners,right =2.5cm of L](D){\small $\Lambda=\langle v_s,\ldots,v_t\rangle$};
    \node[rectmed,rounded corners,below =10cm of A](M){\small Complete graph $K_{n+2}$};
    \node[rectmed,rounded corners,below =1cm of M](N){\small Best complete graph $\pi_{st}^*$};
    \node[rectmed,rounded corners,below =1cm of N](O){\small Improved best $\pi_{st}^*$};
    \node[rectmed,rounded corners,below =1cm of O](P){\small List of Pareto Optimal $\pi_{st}^*$ corresponds to different $\mathbf{w}$};
    \node[draw, diamond,aspect=4.5,below=0.5cm of P,align=center](Q){\small User provide limit\\\small constraints?};
    \node[rectshort,rounded corners,below left=0.5cm and 1.5cm of Q](R){\small $\varepsilon$-constraint method};
    \node[rectshort,rounded corners,below right=0.5cm and 1.5cm of Q](S){\small Ideal point method};
    \node[rectlong,rounded corners,below=1.5cm of Q](T){\small Final solution for user};
    %simple arrow
    \foreach \x/\y in {A/C, B/E, P/Q}   \draw[->,thick](\x)--(\y);

    %bended arrow
    \foreach \from/\height/\to in {A.south/-4/B.north, A.south/-4/D.north, E.south/-12/F.north, E.south/-12/H.north, C.south/-4/L.north, I.south/-5.3/L.north, J.south/-5.3/L.north, D.south/-4/M.north, R.south/-2/T.north, S.south/-2/T.north}
    \draw[->,thick](\from) |- ++(0,\height mm) -| (\to);

    %bended labelled arrow
    \draw[->,thick] (L.south) |- ++(0,-4.1mm) -| (M.north) node[right,pos=0.75,align=left] {\footnotesize perform Dijkstra's or A* \\\footnotesize algorithm $\forall v_i,v_j\in\Lambda$};
    \draw[->,thick] (Q.west) |- ++(0,0mm) -| (R.north) node[above, pos=0.25] {\footnotesize yes};
    \draw[->,thick] (Q.east) |- ++(0,0mm) -| (S.north) node[above, pos=0.25] {\footnotesize no};

    %labelled arrow
    \draw[->,thick](E)--(G)node[right,pos=0.35,align=left]{\footnotesize extracting data for\\\footnotesize each attributes};
    \draw[->,thick](F)--(I)node[right,midway]{\footnotesize normalize};
    \draw[->,thick](G)--(J)node[right,midway]{\footnotesize normalize};
    \draw[->,thick](H)--(K)node[right,midway]{\footnotesize normalize};
    \draw[->,thick](K)--(L)node[right,pos=0.75]{\footnotesize weighting method};
    \draw[->,thick](M)--(N)node[right,midway]{\footnotesize perform RNNA $\forall v_i\in\Lambda$};
    \draw[->,thick](N)--(O)node[right,midway]{\footnotesize perform 2-opt};
    \draw[->,thick,dashed](O)--(P)node[right,midway]{\footnotesize repeat using different $\mathbf{w}$};
\end{tikzpicture}
\caption{Solution Scheme 1}
\end{figure}
\end{document}
4

You can add a scope on the background layer, then define a node relative to current bounding box.west. You can then draw the lines and add the labels at positions relative to this new node in order to keep everything properly aligned.

Edit: As pointed out in the comments, it's better to use \tikzset instead of \tikzstyle. You can also define the styles in the options to tikzpicture, as I have done below. Moreover, you can simplify your code by creating a base style, say myrect, then defining other styles (rectshort, rectmed, and rectlong) in terms of the base style.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,decorations.pathreplacing, positioning, shapes.geometric}

\begin{document}
\pagestyle{empty}
\begin{figure}
\centering
\begin{tikzpicture}[myrect/.style = {draw,rectangle,rounded corners,fill=white!20,text centered,minimum height=1.75em},
rectshort/.style = {myrect,text width=5em}, 
rectmed/.style = {myrect,text width=10em}, 
rectlong/.style = {myrect,text width=15em}, 
]
    \node[rectmed](A){\small User input};
    \node[rectmed,below left=0.75cm and 1.2cm of A](B){\small terrain map};
    \node[rectmed,below=0.5cm of B](E){\small vertex-weighted grid graph $G$};
    \node[rectshort,below=1.5cm of E](G){\small $c^2=\left[\ldots\right]$};
    \node[rectshort,left=0.5cm of G](F){\small $c^1=\left[\ldots\right]$};      
    \node[rectshort,right=0.5cm of G](H){\small $c^3=\left[\ldots\right]$};
    \node[rectshort,below=0.5cm of G](J){\small $\hat{c}^2=\left[\ldots\right]$};
    \node[rectshort,left=0.5cm of J](I){\small $\hat{c}^1=\left[\ldots\right]$};
    \node[rectshort,right=0.5cm of J](K){\small $\hat{c}^3=\left[\ldots\right]$};
    \node[rectshort,right=0.5cm of K](C){\small $\mathbf{w}=(w_1,w_2,w_3)$};
    \node[rectmed,below=1.2cm of K](L){\small grid graph with weighted sum cost $G'$};
    \node[rectshort,right =2.5cm of L](D){\small $\Lambda=\langle v_s,\ldots,v_t\rangle$};
    \node[rectlong,below =10cm of A](M){\small Complete graph $K_{n+2}$};
    \node[rectlong,below =1cm of M](N){\small Best complete graph $\pi_{st}^*$};
    \node[rectlong,below =1cm of N](O){\small Improved best $\pi_{st}^*$};
    \node[rectlong,below =1cm of O](P){\small List of Pareto Optimal $\pi_{st}^*$ corresponds to different $\mathbf{w}$};
    \node[draw, diamond,aspect=4.5,below=0.5cm of P,align=center](Q){\small User provide limit\\\small constraints?};
    \node[rectshort,below left=0.5cm and 1.5cm of Q](R){\small $\varepsilon$-constraint method};
    \node[rectshort,below right=0.5cm and 1.5cm of Q](S){\small Ideal point method};
    \node[rectmed,below=1.5cm of Q](T){\small Final solution for user};
    %simple arrow
    \foreach \x/\y in {A/C, B/E, P/Q}   \draw[->,thick](\x)--(\y);

    %bended arrow
    \foreach \from/\height/\to in {A.south/-4/B.north, A.south/-4/D.north, E.south/-12/F.north, E.south/-12/H.north, C.south/-4/L.north, I.south/-5.3/L.north, J.south/-5.3/L.north, D.south/-4/M.north, R.south/-2/T.north, S.south/-2/T.north}
    \draw[->,thick](\from) |- ++(0,\height mm) -| (\to);

    %bended labelled arrow
    \draw[->,thick] (L.south) |- ++(0,-4.1mm) -| (M.north) node[right,pos=0.75,align=left] {\footnotesize perform Dijkstra's or A* \\\footnotesize algorithm $\forall v_i,v_j\in\Lambda$};
    \draw[->,thick] (Q.west) |- ++(0,0mm) -| (R.north) node[above, pos=0.25] {\footnotesize yes};
    \draw[->,thick] (Q.east) |- ++(0,0mm) -| (S.north) node[above, pos=0.25] {\footnotesize no};

    %labelled arrow
    \draw[->,thick](E)--(G)node[right,pos=0.35,align=left]{\footnotesize extracting data for\\\footnotesize each attributes};
    \draw[->,thick](F)--(I)node[right,midway]{\footnotesize normalize};
    \draw[->,thick](G)--(J)node[right,midway]{\footnotesize normalize};
    \draw[->,thick](H)--(K)node[right,midway]{\footnotesize normalize};
    \draw[->,thick](K)--(L)node[right,pos=0.75]{\footnotesize weighting method};
    \draw[->,thick](M)--(N)node[right,midway]{\footnotesize perform RNNA $\forall v_i\in\Lambda$};
    \draw[->,thick](N)--(O)node(NO)[right,midway]{\footnotesize perform 2-opt};
    \draw[->,thick,dashed](O)--(P)node(OP)[right,midway]{\footnotesize repeat using different $\mathbf{w}$};
%% for phases
\begin{scope}[on background layer]
\node(pre) at (current bounding box.west |- L)[left=1cm]{};
\draw[red](pre |- L) -- (current bounding box.east |- L);
\draw[red](pre |- OP.north) -- (current bounding box.east |- OP.north) node(search)[at start]{};
\node at ($(pre)!0.5!(current bounding box.north west)$)[rotate=90,anchor=north]{Preprocessing};
\node at ($(pre)!0.5!(search)$)[rotate=90,anchor=north]{Path Searching};
\node at ($(search)!0.5!(current bounding box.south west)$)[rotate=90,anchor=north,align=center]{Postprocessing\\Decision Making};
\draw[red,decorate,decoration=brace](I |- NO) -- (I |- pre.south)node[midway,above,sloped]{A};
\draw[red,decorate,decoration=brace](I |- OP.north)--(I |- NO.south)node[midway,above,sloped]{B};
\end{scope}
\end{tikzpicture}
\caption{Solution Scheme 1}
\end{figure}
\end{document}
  • Please avoid \tikzstyle, use \tikzset instead, see: tex.stackexchange.com/questions/52372/… – CarLaTeX Jun 1 at 9:13
  • @CarLaTeX I only added to the existing code since the OP posted a working MWE, but I guess I should have removed \tikzstyle as well (for the sake of best practices). Thanks for pointing that out. I will edit my post. – erik Jun 1 at 14:16

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.