Saltar al contenido

Agregar paréntesis con texto en el diagrama de flujo de Tikz

Hola usuario de nuestra página, hallamos la solución a lo que estabas buscando, deslízate y la obtendrás un poco más abajo.

Solución:

Coloqué los nodos en un ámbito local, el primero se llama “debut”, el segundo se llama “fin”. El código está comentado con %<--, si tiene alguna pregunta, no lo dude.

Nueva respuesta: alineación de llaves

captura de pantalla

documentclassscrartcl

usepackagetikz
usetikzlibraryshapes,arrows,positioning
%<-- decorations library
usetikzlibrarydecorations.pathreplacing,calligraphy
%<-- new syntax of style since Tikz 3.0
tikzsetdecision/.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

begindocument

  begincenter
    resizebox0.4 linewidth!%
      begintikzpicture[node distance = 2cm, auto,decoration=calligraphic brace,amplitude=5mm]%<-- definition of the brace decoration
      beginscope[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^-fracDelta ft_n$;
      endscope%<-- end of local scope "debut"

        node[block, above=3cm of rand]             (rejj) Reject $S_n+1$;
        
        beginscope[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%
  endcenter

enddocument

Respuesta antigua

captura de pantalla

documentclassscrartcl

usepackagetikz
usetikzlibraryshapes,arrows,positioning

usetikzlibrarydecorations.pathreplacing,calligraphy%<-- decorations library
tikzstyledecision = [diamond, draw, fill=blue!20, text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt,on grid]
tikzstyleblock = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em,on grid]
tikzstyleline = [draw, -latex]

begindocument

  begincenter
    resizebox0.4 linewidth!%
      begintikzpicture[node distance = 2cm, auto,decoration=calligraphic brace,amplitude=5mm]%<-- definition of the brace decoration
      beginscope[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^-fracDelta ft_n$;
      endscope%<-- end of local scope "debut"
        
        node[block, above=3cm of rand]             (rejj) Reject $S_n+1$;
        
        beginscope[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?; 
        endscope%<-- end of local scope "fin"
 
        node[block, right=3cm of stcd]                (stop) Stop;


        path[line] (init) --          (nbrh);
        path[line] (nbrh) --          (ovgt);
        path[line] (ovgt) -- nodeyes(accp);
        path[line] (ovgt) -- nodeno (rand);
        path[line] (rand) -- nodeno (rejj);
        path[line] (rejj) --          (nbrh);
        path[line] (rand) %
  endcenter

enddocument

Agregue lo siguiente al final del código

 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
      ;
  

y en el preámbulo la sintaxis correcta es

usetikzlibrarytikzmark, positioning, fit, shapes.misc
usetikzlibrarydecorations.pathreplacing, calc
tikzsetbrace/.style=decorate, decoration=brace,
    brace mirrored/.style=decorate,decoration=brace,mirror,

ingrese la descripción de la imagen aquí

documentclassscrartcl

usepackagetikz
usetikzlibraryshapes,arrows,positioning

tikzstyledecision = [diamond, draw, fill=blue!20, text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt,on grid]
tikzstyleblock = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em,on grid]
tikzstyleline = [draw, -latex]


usetikzlibrarytikzmark, positioning, fit, shapes.misc
usetikzlibrarydecorations.pathreplacing, calc
tikzsetbrace/.style=decorate, decoration=brace,
    brace mirrored/.style=decorate,decoration=brace,mirror,

begindocument

  begincenter
    resizebox0.4 linewidth!- nodeyes(accp);
        path[line] (accp) --          (incr);
        path[line] (incr) --          (stcd);
        path[line] (stcd) -- nodeyes(stop);
        path[line] (stcd) -- ++(-2,0) %
  endcenter


enddocument

Basado en la proposición @js bibra (+1), se sugiere el uso de la chains y quotes bibliotecas, se eliminó la escala de la imagen por resizebox y no usado on grid dibujo:

documentclassscrartcl
usepackagetikz
usetikzlibraryarrows.meta,
                chains,
                decorations.pathreplacing,calligraphy,
                positioning,
                quotes,
                shapes.geometric
                
begindocument
begincenter
    begintikzpicture[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
    beginscope[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
    endscope
% nodes in right column
node   [box, right=of A-2] (rej) Reject $S_n+1$;
node   [decision, at= rej)]   (rand) Accept with $P = e^-fracDelta ft_n$;
node   [box, at=(A-6 -] (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);
endtikzpicture
    endcenter
enddocument

ingrese la descripción de la imagen aquí

Recuerda algo, que tienes permiso de valorar esta noticia si tropezaste tu atascamiento en el momento justo.

¡Haz clic para puntuar esta entrada!
(Votos: 2 Promedio: 4.5)


Tags : /

Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *