Crie um fluxograma em látex

Crie um fluxograma em látex

insira a descrição da imagem aqui

Como criar um fluxograma como este em látex? Até agora não consegui nada próximo disso. Meu código é o seguinte.

    \documentclass{article}
    \usepackage{tikz}
    
    \begin{document}
    
    \begin{tikzpicture}[node distance=2cm, auto,
      level1/.style={rectangle, draw, fill=red!20, rounded corners, text width=4em, text centered, minimum height=2em},
      level2/.style={rectangle, draw, fill=blue!20, rounded corners, text width=4em, text centered, minimum height=2em},
      level3/.style={rectangle, draw, fill=green!20, rounded corners, text width=4em, text centered, minimum height=2em}]
    
      % Root node
      \node [level1] (root) {Root};
    
      % Level 2 nodes
      \node [level2, right of=root] (node1) {Node 1};
      \node [level2, right of=node1] (node2) {Node 2};
      \node [level2, right of=node2] (node3) {Node 3};
      \node [level2, right of=node3] (node4) {Node 4};
      \node [level2, right of=node4] (node5) {Node 5};
    
      % Level 3 nodes
      \node [level3, below of=node1, yshift=-1cm] (child1) {Child 1};
      \node [level3, below of=node2, yshift=-1cm] (child2) {Child 2};
      \node [level3, below of=node3, yshift=-1cm] (child3) {Child 3};
      \node [level3, below of=node4, yshift=-1cm] (child4) {Child 4};
      \node [level3, below of=node5, yshift=-1cm] (child5) {Child 5};
    
      % Arrows
      \foreach \from in {root}
        \foreach \to in {node1, node2, node3, node4, node5}
          \draw [->] (\from) -- (\to);
      \foreach \from in {node1, node2, node3, node4, node5}
        \foreach \to in {child1, child2, child3}
          \draw [->] (\from) -- (\to);
    
    \end{tikzpicture}
    
    \end{document}

RESULTADO

Responder1

Aqui está uma forestsolução.

insira a descrição da imagem aqui

\documentclass{article}

\usepackage{forest}
\useforestlibrary{edges}

\begin{document}

\begin{forest}
forked edges,
for tree={
    grow'=0,
    align=center,
    minimum width=3cm,
    anchor=center,
    inner xsep=3mm,
    rounded corners,
    font=\small,
    if level=1{fill=orange, text=white}
        {if level=2{fill=brown, text=white}{draw=red}}
}
[Root node, rotate=90, fill=red, text=white
    [level 1 node
        [level 2 node
            [Some very long reference]
        ]
        [level 2 node
            [Some very long reference\\with two lines]
        ]
    ]
    [level 1 node
        [level 2 node
            [Another even longer reference\\with two lines]
        ]
        [level 2 node
            [Some very long reference\\with two lines]
        ]
        [level 2 node\\has two lines
            [Some reference[Another reference]]
            [Some reference\\with two lines[Another reference\\with two lines]]
        ]
    ]
    [level 1 node
        [level 2 node
            [A very very very long long long reference\\with two lines]
        ]
        [level 2 node
            [A very very very long long long reference]
        ]
    ]
    [level 1 node
        [level 2 node
            [A very very very long long long reference]
        ]
        [level 2 node
            [A long reference]
        ]
    ]
    [level 1 node
        [level 2 node
            [A very very very long long long reference]
        ]
        [level 2 node
            [A very very very long long long reference]
        ]
    ]
]
\end{forest}

\end{document}

Responder2

Há muitas maneiras de fazer isso, por exemplo, usando o child-approach do pgfmanual, usando package forest, usando a matrixpara colocar nós, usando tiklzlibrary positioningetc.

Quando você é iniciante sugiro fazer mais objeto por objeto, com alto grau de controle. Então basicamente o seguinte:

  • coloque os nós de uma maneira razoável
  • desenha as conexões necessárias

Documentei as etapas relevantes nos comentários, com foco na parte interessante do meio. EUsugerirtentar repeti-los do zero por motivos de treinamento e ver como o código evolui de simples para refinado. EUsugerirpara procurar esses comandos em paralelo no pgfmanual.

O primeiro código mostra o resultado, assim que terminar o posicionamento e as conexões. A segunda é uma questão de embelezamento, ou seja, introdução de cor, etc.

Vários parâmetros existem para ajustes. Além dos ramos, todos eles estão localizados na seção de estilo. Portanto, as mudanças quase sempre dão certo. Aquele para as ramificações poderia e deveria ser movido \newcommandpara refatoração adicional.

Concluindo nós e conexões

Começando de trás para frente, trabalhe dos filhos mais à direita até a raiz.

Girar o nó raiz é complicado, então deixei como está por enquanto.

Para as conexões há duas coisas:

  • testes comentados, para verificar se há código bom e refatorar em um loop, usando pares de nós (bem, seus nomes)
  • o mesmo para os ramos, com a introdução de um ponto intermediário como coordenada relativa

res1

% ~~~ makes development much easier ~~~~~~~~~~~~~~~~~~
\documentclass[10pt,border=3mm,tikz]{standalone}

% ~~~ PROCESS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%       care for positioning text, first
% 1)    start with node at (0,0), ignoring all colors etc.
% 2)    put next node above it, introduce style up
% 3)    continue, introduce style and nodes for dn
% 4)    introduce brown child level as nodes + style lft
% 4b)   making nodes width the same, i.e. adjust style lft
% 5)    introducing orange children, style lftb reuses lft
% 6)    introducing ROOT and extra
% 7)    adding simple and branched connections


\begin{document}
 \begin{tikzpicture}[% ~~~ introducing styles as suitable
        up/.style={draw,anchor=south west,yshift=2mm},
        dn/.style={draw,anchor=north west,yshift=-2mm},
        lft/.style={draw,anchor=east,xshift=-4mm,minimum width=2cm},
        lftb/.style={lft,minimum width=32mm,yshift=-4mm},
        rt/.style={draw,anchor=west,xshift=4mm},
        root/.style={draw,xshift=-10mm,yshift=-9mm,
                     rotate=0,anchor=east},
    ]
 
    % ~~~ starting backwards with "rightmost" child level ~~~
    % ~~~ upwards
    \node[draw] (D0) at (0,0)           {Denoisung};
    \node[up]   (D1) at (D0.north west) {HDR};
    \node[up]   (D2) at (D1.north west) {Semantic NeRF};

    % ~~~ downwards
    \node[dn]   (D-1) at (D0.south west) {GIRAFFE};
    \node[dn]   (D-2) at (D-1.south west){Dream Fusion};
    
    % ~~~ brown children ~~~~~
    \node[lft]  (C-1) at (D-2.west)      {Diffusion};
    \node[lft]  (C1)  at (D1.west)       {Semantics};
    \node[lft]  (C2)  at (D2.west)       {Editing};
    % ~~~ this one is special ~~~~~~~~~
    \node[lft,yshift=-4mm] (C0)  at (D0.west) {Functional};
    
    % ~~~ orange children ~~~~~~~~~~    
    \node[lftb] (B0) at (C0.west)        {Generative Models};
    \node[lftb] (B1) at (C2.west)        {Image Processing};
    
    % ~~~ ROOT ~~~~~~~~~~
    \node[root] (RT) at (B1.west) {Applications};
    
    % ~~~ extra ~~~~~~~~~
    \node[rt] (X0) at (D0.east) {RawNeRF};
    
    % ~~~ SIMPLE connections ~~~~~~~~~
%   \draw (C2) -- (D2); 
%   \draw (C1) -- (D1); 
%   now refactored, i.e. as loop
    \foreach \a/\b in {C2/D2, C1/D1, D0/X0, C-1/D-2}
        \draw (\a) -- (\b);
    
    % ~~~ branched connections ~~~~~~~~
%   \draw (C0.east) -- +(.2,0) |-  (D0.west);
%   \draw (C0.east) -- +(.2,0) |-  (D-1.west);
%   now refactored, i.e. as loop
    \foreach \a/\b in  {C0/D0, C0/D-1,
                        B1/C2, B1/C1, B0/C0, B0/C-1,
                        RT/B1, RT/B0}
        \draw (\a.east) -- +(.2,0) |- (\b.west);    
    
 \end{tikzpicture}
\end{document}

Embelezando

Isso é quase chato agora:

  • definir estilos para os vários níveis
  • adicione esses estilos aos nós relevantes

Pode ser uma boa ideia excluir as tentativas ao adicionar mais ao diagrama. Para fazer isso, basta seguir os padrões:

  • novo nó, agora com combinações de estilos corretas e novos nomes de nós
  • adicionando conexões necessárias a ambos \draw-loops
  • dar pequenos passos ao fazê-lo, para reconhecer e resolver problemas antecipadamente

EUsugerirrepensar, SE for uma boa ideia introduzir texto com várias linhas. Embora seja possível, é provável que você precise reajustar vários estilos, talvez até mudar algumas abordagens. Normalmente: menos é mais - mais ou menos...

res2

% ~~~ makes development much easier ~~~~~~~~~~~~~~~~~~
\documentclass[10pt,border=3mm,tikz]{standalone}

% ~~~ PROCESS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%       now let's take care of colors and shapes
% 8)    define styles nd etc. AND add to the relevant nodes


\begin{document}
 \begin{tikzpicture}[% ~~~ introducing styles as suitable
        up/.style={draw,anchor=south west,yshift=2mm},
        dn/.style={draw,anchor=north west,yshift=-2mm},
        lft/.style={draw,anchor=east,xshift=-4mm,
                    minimum width=2cm},
        lftb/.style={lft,minimum width=32mm,yshift=-4mm},
        rt/.style={draw,anchor=west,xshift=4mm},
        root/.style={draw,xshift=-10mm,yshift=-9mm,
                     rotate=0,anchor=east},
        % ~~~ now the colors etc. ~~~~~~~~~~
        nd/.style={draw=red,rounded corners},
        nc/.style={draw=none,rounded corners,fill=brown!30},
        nb/.style={draw=none,rounded corners,fill=orange!30},
        nr/.style={draw=none,rounded corners,fill=red,
                   text=white,},% not recommended !
    ]
 
    % ~~~ starting backwards with "rightmost" child level ~~~
    % ~~~ upwards
    \node[draw,nd] (D0) at (0,0)           {Denoisung};
    \node[up,nd]   (D1) at (D0.north west) {HDR};
    \node[up,nd]   (D2) at (D1.north west) {Semantic NeRF};

    % ~~~ downwards
    \node[dn,nd]   (D-1) at (D0.south west) {GIRAFFE};
    \node[dn,nd]   (D-2) at (D-1.south west){Dream Fusion};
    
    % ~~~ brown children ~~~~~
    \node[lft,nc]  (C-1) at (D-2.west)      {Diffusion};
    \node[lft,nc]  (C1)  at (D1.west)       {Semantics};
    \node[lft,nc]  (C2)  at (D2.west)       {Editing};
    % ~~~ this one is special ~~~~~~~~~
    \node[lft,yshift=-4mm,nc] (C0)  at (D0.west) {Functional};
    
    % ~~~ orange children ~~~~~~~~~~    
    \node[lftb,nb] (B0) at (C0.west)         {Generative Models};
    \node[lftb,nb] (B1) at (C2.west)         {Image Processing};
    
    % ~~~ ROOT ~~~~~~~~~~
    \node[root,nr] (RT) at (B1.west) {Applications};
    
    % ~~~ extra ~~~~~~~~~
    \node[rt,nd] (X0) at (D0.east) {RawNeRF};
    
    % ~~~ SIMPLE connections ~~~~~~~~~
%   \draw (C2) -- (D2); 
%   \draw (C1) -- (D1); 
%   now refactored, i.e. as loop
    \foreach \a/\b in {C2/D2, C1/D1, D0/X0, C-1/D-2}
        \draw (\a) -- (\b);
    
    % ~~~ branched connections ~~~~~~~~
%   \draw (C0.east) -- +(.2,0) |-  (D0.west);
%   \draw (C0.east) -- +(.2,0) |-  (D-1.west);
%   now refactored, i.e. as loop
    \foreach \a/\b in  {C0/D0, C0/D-1,
                        B1/C2, B1/C1, B0/C0, B0/C-1,
                        RT/B1, RT/B0}
        \draw (\a.east) -- +(.2,0) |- (\b.west);    
    
 \end{tikzpicture}
\end{document}

informação relacionada