Saltar al contenido

¿Cómo dibujar un diagrama jerárquico en tikz?

Esta crónica ha sido analizado por nuestros expertos así aseguramos la exactitud de nuestro post.

Solución:

La próxima vez, tenga en cuenta que debe investigar las soluciones usted mismo y publicar un MWE que al menos proporcione el marco del documento y, por ejemplo, el texto para los nodos de su imagen. (Esto es mucho más fácil que copiar una imagen para personas que deseen ayudarlo).

Esta respuesta usa forest para crear el diagrama como un árbol. Utiliza sombreado para dar un poco de profundidad a los nodos y al shadows biblioteca para mejorar este efecto. Dos phantom Los niños se utilizan para ayudar a alinear los nodos finales del árbol y las líneas de conexión al primero de estos se agregan después de que se completa el árbol, ya que este nodo tiene cuatro padres.

diagrama como árbol

documentclass[border=5pt]standalone

usepackageforest
usetikzlibraryarrows.meta, shapes.geometric, calc, shadows

colorletmygreengreen!75!black
colorletcol1inred!30
colorletcol1outred!40
colorletcol2inmygreen!40
colorletcol2outmygreen!50
colorletcol3inblue!30
colorletcol3outblue!40
colorletcol4inmygreen!20
colorletcol4outmygreen!30
colorletcol5inblue!10
colorletcol5outblue!20
colorletcol6inblue!20
colorletcol6outblue!30
colorletcol7outorange
colorletcol7inorange!50
colorletcol8outorange!40
colorletcol8inorange!20
colorletlinecolblue!60

begindocument
pgfkeys/forest,
  rect/.append style=rectangle, rounded corners=2pt, inner color=col6in, outer color=col6out,
  ellip/.append style=ellipse, inner color=col5in, outer color=col5out,
  orect/.append style=rect, font=sffamilybfseriesLARGE, text width=325pt, text centered, minimum height=10pt, outer color=col7out, inner color=col7in,
  oellip/.append style=ellip, inner color=col8in, outer color=col8out, font=sffamilybfserieslarge, text centered,

beginforest
  for tree=
      font=sffamilybfseries,
      line width=1pt,
      draw=linecol,
      ellip,
      align=center,
      child anchor=north,
      parent anchor=south,
      drop shadow,
      l sep+=12.5pt,
      edge path=
        noexpandpath[color=linecol, rounded corners=5pt, >=Stealth[length=10pt], line width=1pt, ->, forestoptionedge]
          (!u.parent anchor) -- +(0,-5pt) -,
      where level=3tier=tier3,
      where level=0l sep-=15pt,
      where level=1
        if n=1
          edge path=
            noexpandpath[color=linecol, rounded corners=5pt, >=Stealth[length=10pt], line width=1pt, ->, forestoptionedge]
              (!u.west) -,
        
          edge path=
            noexpandpath[color=linecol, rounded corners=5pt, >=Stealth[length=10pt], line width=1pt, ->, forestoptionedge]
              (!u.east) -,
        
      ,
  
  [Compressed Sensing\Theory, inner color=col1in, outer color=col1out
    [Projection Matrix\Theory, inner color=col2in, outer color=col2out
      [Optimise Projection\Matrix, inner color=col4in, outer color=col4out]
      [Reduce Number of\Measurements, inner color=col4in, outer color=col4out]
    ]
    [Reconstruction\Algorithms, inner color=col3in, outer color=col3out
      [Convex Relaxation
        [Sparse Signal\Estimate, rect, name=sse1
        ]
      ]
      [Greedy Pursuits
        [Sparse Signal\Estimate, rect, name=sse2
        ]
      ]
      [, phantom, calign with current
        [A\B, phantom
          [Our Work, orect, name=us
            [Improved Sparse Signal Estimate!, oellip
            ]
          ]
        ]
      ]
      [Non-Convex\Minimisation Methods
        [Sparse Signal\Estimate, rect, name=sse3
        ]
      ]
      [Combinatorial\Algorithms
        [Sparse Signal\Estimate, rect, name=sse4
        ]
      ]
    ]
  ]
  beginscope[color=linecol, rounded corners=5pt, >=Stealth[length=10pt], line width=1pt, ->]
    draw (sse2.south) -- (us.north -| sse2.south);
    draw (sse3.south) -- (us.north -| sse3.south);
    coordinate (c1) at ($(sse1.south)!2/5!(sse2.south)$);
    coordinate (c2) at ($(sse3.south)!2/5!(sse4.south)$);
    draw (sse1.south) -- +(0,-10pt) -| (us.north -| c1);
    draw (sse4.south) -- +(0,-10pt) -| (us.north -| c2);
  endscope
endforest
enddocument

Eche un vistazo aquí: Texample – Diagrama de flujo simple

Las bibliotecas necesarias, como en este ejemplo, son usetikzlibraryshapes,arrows.

Editar:
Tomado de Texample:

usepackagetikz
usetikzlibraryshapes,arrows
begindocument

% Define block styles
tikzstyledecision = [diamond, draw, fill=blue!20, text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
tikzstyleblock = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em]
tikzstyleline = [draw, -latex']
tikzstylecloud = [draw, ellipse,fill=red!20, node distance=3cm, minimum height=2em]

begintikzpicture[node distance = 2cm, auto]
% Place nodes
node [block] (init) initialize model;
node [cloud, left of=init] (expert) expert;
node [cloud, right of=init] (system) system;
node [block, below of=init] (identify) identify candidate models;
node [block, below of=identify] (evaluate) evaluate candidate models;
node [block, left of=evaluate, node distance=3cm] (update) update model;
node [decision, below of=evaluate] (decide) is best candidate better?;
node [block, below of=decide, node distance=3cm] (stop) stop;
% Draw edges
path [line] (init) -- (identify);
path [line] (identify) -- (evaluate);
path [line] (evaluate) -- (decide);
path [line] (decide) -| node [near start] yes (update);
path [line] (update) |- (identify);
path [line] (decide) -- node no(stop);
path [line,dashed] (expert) -- (init);
path [line,dashed] (system) -- (init);
path [line,dashed] (system) |- (evaluate);
endtikzpicture
enddocument

Editar 2: En el caso específico, mi código se ve así.

usepackagetikz
usetikzlibraryshapes,arrows,trees,calc
begindocument
% Define block styles
tikzstyleblock = [rectangle, draw, text width=2.5cm, text centered, rounded corners, minimum height=4em,fill=blue!20]
tikzstyleline = [draw,thick, -latex']
tikzstylecloud = [draw, ellipse, text width=2.5cm, text centered]
tikzstyleedge from parent=[->,thick,draw]

begintikzpicture[auto,edge from parent fork down]
tikzstylelevel 1=[sibling distance=180mm,level distance=18ex] 
tikzstylelevel 2=[sibling distance=55mm,level distance=24ex] 
% Place nodes
node [cloud,fill=red!40] (cst) Compressed Sensing Theory
childnode [cloud,fill=green!40] (pmt) Projection Matrix Theory
    childnode [cloud,fill=green!20] (opm) Optimize Projection Matrix
    childnode [cloud,fill=green!20] (rnm) Reduce Number of Measurements

childnode [cloud,fill=blue!40] (ra) Reconstruction Algorithms
    childnode [cloud,fill=blue!20] (cr) Convex Relaxation
    childnode [cloud,fill=blue!20] (gp) Greedy Pursuit
    childnode [cloud,fill=blue!20] (ncmm) Non-Convex Minimization Methods
    childnode [cloud,fill=blue!20] (ca) Combinatorial Algorithms
;
node[block,yshift=-1cm,below of= cr](sse1)Sparse Signal Estimate;
node[block,yshift=-1cm,below of= gp](sse2)Sparse Signal Estimate;
node[block,yshift=-1cm,below of= ncmm](sse3)Sparse Signal Estimate;
node[block,yshift=-1cm,below of= ca](sse4)Sparse Signal Estimate;
node[below of= ra,yshift=-8cm,rectangle, draw, text width=16cm, text centered, rounded corners, minimum height=3em,fill=orange!40](ow)Our Work;
node[below of= ow,yshift=-1cm,rectangle, draw, text width=8cm, text centered, rounded corners, minimum height=3em,fill=orange!20](isse)Improve Sparse Signal Estimate;
%% Draw edges
path [line] (cr.south) -- (sse1.north);
path [line] (gp.south) -- (sse2.north);
path [line] (ncmm.south) -- (sse3.north);
path [line] (ca.south) -- (sse4.north);
path [line] (sse1)--($(sse1.south)-(0,0.5)$) -| (ow.175);
path [line] (sse2)--($(sse2.south)-(0,0.5)$) -| (ow.150);
path [line] (sse3)--($(sse3.south)-(0,0.5)$) -| (ow.30);
path [line] (sse4)--($(sse4.south)-(0,0.5)$) -| (ow.5);
path [line] (ow.south) -- (isse.north);
endtikzpicture
enddocument

Resultado

Si para ti ha sido de ayuda este post, sería de mucha ayuda si lo compartes con otros seniors de esta manera nos ayudas a dar difusión a nuestra información.

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



Utiliza Nuestro Buscador

Deja una respuesta

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