4

I have adapted the following flow-chart from another question, I would like to know if it is possible to add parenthesis to describe the step in the flow chart like this?:

enter image description here

\documentclass{scrartcl}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}

\tikzstyle{decision} = [diamond, draw, fill=blue!20, text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt,on grid]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em,on grid]
\tikzstyle{line} = [draw, -latex]

\begin{document}

  \begin{center}
    \resizebox{0.4 \linewidth}{!}{%
      \begin{tikzpicture}[node distance = 2cm, auto]
        \node[block]                                (init) {Init $n=0$, $T_0$, and $S_0$};
        \node[block, below= of init]                (nbrh) {$S_{n+1}=N(S_n)$};
        \node[decision, below= of nbrh]             (ovgt) {$f(S_{n+1}) \le f(S_n)$};
        \node[block, below=2.5cm of ovgt]           (accp) {Accept $S_{n+1}$};
        \node[decision, right= 3.5cm of ovgt]       (rand) {Accept with $P = e^{-\frac{\Delta f}{t_n}}$};
        \node[block, above=3cm of rand]             (rejj) {Reject $S_{n+1}$};
        \node[block, below= of accp]                (incr) {$T_{n+1} = K(T_n)$ and $n=n+1$};
        \node[decision, below=2.5cm of incr]              (stcd) {Stop?};  
        \node[block, right=3cm of stcd]                (stop) {Stop};


        \path[line] (init) --          (nbrh);
        \path[line] (nbrh) --          (ovgt);
        \path[line] (ovgt) -- node{yes}(accp);
        \path[line] (ovgt) -- node{no} (rand);
        \path[line] (rand) -- node{no} (rejj);
        \path[line] (rejj) --          (nbrh);
        \path[line] (rand) |- node{yes}(accp);
        \path[line] (accp) --          (incr);
        \path[line] (incr) --          (stcd);
        \path[line] (stcd) -- node{yes}(stop);
        \path[line] (stcd) -- ++(-2,0) |- node[pos=.25]{no}  (nbrh);
      \end{tikzpicture}%
    }%
  \end{center}


\end{document}
4

I placed the nodes in a local scope, the first one is called "debut", the second one is called "fin". The code is commented with %<--, if you have any questions, don't hesitate.

New answer: alignment of braces

screenshot

\documentclass{scrartcl}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
%<-- decorations library
\usetikzlibrary{decorations.pathreplacing,calligraphy}
%<-- new syntax of style since Tikz 3.0
\tikzset{decision/.style={diamond, draw, fill=blue!20, text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt,on grid},
        block/.style={rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em,on grid},
        line/.style={draw, -latex}}

\begin{document}

  \begin{center}
    \resizebox{0.4 \linewidth}{!}{%
      \begin{tikzpicture}[node distance = 2cm, auto,decoration={calligraphic brace,amplitude=5mm}]%<-- definition of the brace decoration
      \begin{scope}[local bounding box=debut]%<--local scope "debut"
      \node[block]                                (init) {Init $n=0$, $T_0$, and $S_0$};
        \node[block, below= of init]                (nbrh) {$S_{n+1}=N(S_n)$};
        \node[decision, below= of nbrh]             (ovgt) {$f(S_{n+1}) \le f(S_n)$};
        \node[block, below=2.5cm of ovgt]           (accp) {Accept $S_{n+1}$};
        \node[decision, right= 3.5cm of ovgt]       (rand) {Accept with $P = e^{-\frac{\Delta f}{t_n}}$};
      \end{scope}%<-- end of local scope "debut"

        \node[block, above=3cm of rand]             (rejj) {Reject $S_{n+1}$};
        
        \begin{scope}[local bounding box=fin]%<-- local scope "fin"
        
        \node[block, below= of accp]                (incr) {$T_{n+1} = K(T_n)$ and $n=n+1$};
        \node[decision, below=2.5cm of incr]              (stcd) {Stop?}; 
        \node[inner sep=0pt,outer sep=0pt] at (debut.south west|-incr.north west){};%<-- alignment of the "fin" scope to the previous "debut" scope.
        \end{scope}%<-- end of local scope "fin"

        \node[block, right=3cm of stcd]                (stop) {Stop};


        \path[line] (init) --          (nbrh);
        \path[line] (nbrh) --          (ovgt);
        \path[line] (ovgt) -- node{yes}(accp);
        \path[line] (ovgt) -- node{no} (rand);
        \path[line] (rand) -- node{no} (rejj);
        \path[line] (rejj) --          (nbrh);
        \path[line] (rand) |- node{yes}(accp);
        \path[line] (accp) --          (incr);
        \path[line] (incr) --          (stcd);
        \path[line] (stcd) -- node{yes}(stop);
        \path[line] (stcd) -- ++(-2,0) |- node[pos=.25]{no}  (nbrh);
        
        % brace décoration
        \draw[decorate,ultra thick,transform canvas={xshift=-20mm}] (debut.south west)--(debut.north west)node[midway,left,xshift=-1em]{$S_1$};
        \draw[decorate,ultra thick,transform canvas={xshift=-20mm}] (fin.south west)--(fin.north west)node[midway,left,xshift=-1em]{$S_1$};
      \end{tikzpicture}%
    }%
  \end{center}

\end{document}

Old answer

screenshot

\documentclass{scrartcl}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}

\usetikzlibrary{decorations.pathreplacing,calligraphy}%<-- decorations library
\tikzstyle{decision} = [diamond, draw, fill=blue!20, text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt,on grid]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em,on grid]
\tikzstyle{line} = [draw, -latex]

\begin{document}

  \begin{center}
    \resizebox{0.4 \linewidth}{!}{%
      \begin{tikzpicture}[node distance = 2cm, auto,decoration={calligraphic brace,amplitude=5mm}]%<-- definition of the brace decoration
      \begin{scope}[local bounding box=debut]%<--local scope "debut"
      \node[block]                                (init) {Init $n=0$, $T_0$, and $S_0$};
        \node[block, below= of init]                (nbrh) {$S_{n+1}=N(S_n)$};
        \node[decision, below= of nbrh]             (ovgt) {$f(S_{n+1}) \le f(S_n)$};
        \node[block, below=2.5cm of ovgt]           (accp) {Accept $S_{n+1}$};
        \node[decision, right= 3.5cm of ovgt]       (rand) {Accept with $P = e^{-\frac{\Delta f}{t_n}}$};
      \end{scope}%<-- end of local scope "debut"
        
        \node[block, above=3cm of rand]             (rejj) {Reject $S_{n+1}$};
        
        \begin{scope}[local bounding box=fin]%<-- local scope "fin"
        \node[block, below= of accp]                (incr) {$T_{n+1} = K(T_n)$ and $n=n+1$};
        \node[decision, below=2.5cm of incr]              (stcd) {Stop?}; 
        \end{scope}%<-- end of local scope "fin"
 
        \node[block, right=3cm of stcd]                (stop) {Stop};


        \path[line] (init) --          (nbrh);
        \path[line] (nbrh) --          (ovgt);
        \path[line] (ovgt) -- node{yes}(accp);
        \path[line] (ovgt) -- node{no} (rand);
        \path[line] (rand) -- node{no} (rejj);
        \path[line] (rejj) --          (nbrh);
        \path[line] (rand) |- node{yes}(accp);
        \path[line] (accp) --          (incr);
        \path[line] (incr) --          (stcd);
        \path[line] (stcd) -- node{yes}(stop);
        \path[line] (stcd) -- ++(-2,0) |- node[pos=.25]{no}  (nbrh);
        
        % brace décoration
        \draw[decorate,ultra thick,transform canvas={xshift=-20mm}] (debut.south west)--(debut.north west)node[midway,left,xshift=-1em]{$S_1$};
        \draw[decorate,ultra thick,transform canvas={xshift=-20mm}] (fin.south west)--(fin.north west)node[midway,left,xshift=-1em]{$S_1$};
      \end{tikzpicture}%
    }%
  \end{center}

\end{document}
| improve this answer | |
4

Add the following at the end of the code

 \draw[brace mirrored, ultra thick]($(init.north west)+(-2cm,0cm)$)--($(accp.south west)+(-2cm,0cm)$) 
      node[midway, left]{S1}
      ;
       \draw[brace mirrored, ultra thick]($(incr.north west)+(-2cm,0cm)$)--($(stcd.west)+(-2cm,-1cm)$) 
      node[midway, left]{S2}
      ;
  

and in the preamble the correct syntax is

\usetikzlibrary{tikzmark, positioning, fit, shapes.misc}
\usetikzlibrary{decorations.pathreplacing, calc}
\tikzset{brace/.style={decorate, decoration={brace}},
    brace mirrored/.style={decorate,decoration={brace,mirror}},
}

enter image description here

\documentclass{scrartcl}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}

\tikzstyle{decision} = [diamond, draw, fill=blue!20, text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt,on grid]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em,on grid]
\tikzstyle{line} = [draw, -latex]


\usetikzlibrary{tikzmark, positioning, fit, shapes.misc}
\usetikzlibrary{decorations.pathreplacing, calc}
\tikzset{brace/.style={decorate, decoration={brace}},
    brace mirrored/.style={decorate,decoration={brace,mirror}},
}
\begin{document}

  \begin{center}
    \resizebox{0.4 \linewidth}{!}{%
      \begin{tikzpicture}[node distance = 2cm, auto]
        \node[block]                                (init) {Init $n=0$, $T_0$, and $S_0$};
        \node[block, below= of init]                (nbrh) {$S_{n+1}=N(S_n)$};
        \node[decision, below= of nbrh]             (ovgt) {$f(S_{n+1}) \le f(S_n)$};
        \node[block, below=2.5cm of ovgt]           (accp) {Accept $S_{n+1}$};
        \node[decision, right= 3.5cm of ovgt]       (rand) {Accept with $P = e^{-\frac{\Delta f}{t_n}}$};
        \node[block, above=3cm of rand]             (rejj) {Reject $S_{n+1}$};
        \node[block, below= of accp]                (incr) {$T_{n+1} = K(T_n)$ and $n=n+1$};
        \node[decision, below=2.5cm of incr]              (stcd) {Stop?};  
        \node[block, right=3cm of stcd]                (stop) {Stop};


        \path[line] (init) --          (nbrh);
        \path[line] (nbrh) --          (ovgt);
        \path[line] (ovgt) -- node{yes}(accp);
        \path[line] (ovgt) -- node{no} (rand);
        \path[line] (rand) -- node{no} (rejj);
        \path[line] (rejj) --          (nbrh);
        \path[line] (rand) |- node{yes}(accp);
        \path[line] (accp) --          (incr);
        \path[line] (incr) --          (stcd);
        \path[line] (stcd) -- node{yes}(stop);
        \path[line] (stcd) -- ++(-2,0) |- node[pos=.25]{no}  (nbrh);
      
      \draw[brace mirrored, ultra thick]($(init.north west)+(-2cm,0cm)$)--($(accp.south west)+(-2cm,0cm)$) 
      node[midway, left]{S1}
      ;
       \draw[brace mirrored, ultra thick]($(incr.north west)+(-2cm,0cm)$)--($(stcd.west)+(-2cm,-1cm)$) 
      node[midway, left]{S2}
      ;
  

\end{tikzpicture}%
    }%
  \end{center}


\end{document}
| improve this answer | |
2

Based on the @js bibra proposition (+1), suggested are the use of the chains and quotes libraries, removed scaling of image by resizebox and not used on grid drawing:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                decorations.pathreplacing,calligraphy,
                positioning,
                quotes,
                shapes.geometric
                }
\begin{document}
\begin{center}
    \begin{tikzpicture}[auto,
    node distance = 6mm and 15mm,
      start chain = A going below,
       arr/.style = {-Stealth},
every edge/.style = {draw, arr},
        BC/.style = {decorate,  % Brace Calligraphic
                     decoration={calligraphic brace, amplitude=3mm,
                                 raise=1mm, mirror},
                     very thick, pen colour={black}
                    },
       box/.style = {draw, rounded corners, fill=blue!20, align=center,
                     minimum height=4em, text width=6em},
  decision/.style = {diamond, aspect=1.5, draw, fill=blue!20,
                    inner xsep=-3pt, text width=5.4em, align=center},
                        ]
% nodes
    \begin{scope}[nodes={on chain=A, join=by arr}]
\node   [box]       {Init $n=0$, $T_0$, and $S_0$};     % name=A-1
\node   [box]       {$S_{n+1}=N(S_n)$};
\node   [decision]  {$f(S_{n+1}) \le f(S_n)$};
\node   [box]       {Accept $S_{n+1}$};
\node   [box]       {$T_{n+1} = K(T_n)$ and $n=n+1$};
\node   [decision]  {Stop?};                            % A-6
    \end{scope}
% nodes in right column
\node   [box, right=of A-2] (rej) {Reject $S_{n+1}$};
\node   [decision, at={(A-3 -| rej)}]   (rand) {Accept with $P = e^{-\frac{\Delta f}{t_n}}$};
\node   [box, at={(A-6 -| rej)}] (stop) {Stop};
% edge labels and connections not considered in join macro
\path   (A-3)   edge ["yes"] (A-4) 
        (A-3)   edge ["no"]  (rand)
        (rand)  edge ["no"]  (rej)
        (rej)   edge         (A-2)  
        (A-6)   edge ["yes"]  (stop);
\draw[arr]  (rand)  |- node[pos=0.75] {yes} (A-4);
\draw[arr]  (A-6.west) to ["no" '] ++(-1,0) |- (A-2);
% braces
\draw[BC]   ([xshift=-12mm] A-1.north west) coordinate (aux) -- 
                    node[midway,left=5mm]{$S_1$}
            (aux |- A-4.south);
\draw[BC]   (aux |- A-5.north) --
                    node[midway,left=5mm]{$S_2$}
            (aux |- A-6.south);
\end{tikzpicture}
    \end{center}
\end{document}

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.