라텍스에서 순서도 만들기

라텍스에서 순서도 만들기

여기에 이미지 설명을 입력하세요

라텍스에서 이와 같은 순서도를 만드는 방법은 무엇입니까? 지금까지 나는 이것에 가까운 어떤 것도 달성할 수 없었습니다. 내 코드는 다음과 같습니다.

    \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}

결과

답변1

여기에 해결책이 있습니다 forest.

여기에 이미지 설명을 입력하세요

\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}

답변2

이를 수행하는 방법에는 여러 가지가 있습니다(예: childpgfmanual의 -접근 방식 사용, package 사용 forest, a를 사용하여 matrix노드 배치, tiklzlibrary 사용 positioning등).

초보자라면 높은 수준의 제어를 통해 개체별로 더 많은 작업을 수행하는 것이 좋습니다. 따라서 기본적으로 다음과 같습니다.

  • 노드를 합리적인 방법으로 배치
  • 필요한 연결을 그립니다.

중간에 흥미로운 부분에 초점을 맞춰 관련 단계를 댓글에 문서화했습니다. 나제안하다훈련을 위해 처음부터 이를 반복해 보고, 코드가 단순한 코드에서 세련된 코드로 어떻게 발전하는지 확인합니다. 나제안하다pgfmanual에서 이러한 명령을 병렬로 찾아보십시오.

첫 번째 코드는 배치 및 연결이 완료되면 결과를 보여줍니다. 두 번째는 아름답게 하는 것, 즉 색상을 소개하는 것입니다.

조정을 위한 여러 매개변수가 있습니다. 브랜치 외에도 모두 스타일 섹션에 현지화되어 있습니다. 따라서 변경 사항은 거의 항상 올바르게 진행됩니다. \newcommand추가 리팩토링을 위해 분기에 대한 항목을 로 이동할 수 있고 이동해야 합니다 .

노드 및 연결 완료

뒤로 시작하여 가장 오른쪽 자식부터 루트까지 작업합니다.

루트 노드를 회전시키는 것이 까다로워 일단은 그대로 두었습니다.

연결에는 두 가지가 있습니다.

  • 좋은 코드를 확인하고 노드 쌍(음, 이름)을 사용하여 루프로 리팩토링하기 위한 주석 처리된 시험
  • 가지에 대해서도 동일하며 하나의 중간 지점을 상대 좌표로 도입합니다.

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}

아름답게

이제 거의 지루해졌습니다.

  • 다양한 레벨에 대한 스타일 정의
  • 관련 노드에 해당 스타일을 추가하십시오.

다이어그램에 더 추가할 때 시도를 실제로 삭제하는 것이 좋습니다. 그렇게 하려면 다음 패턴을 따르십시오.

  • 이제 올바른 스타일 조합과 새 노드 이름이 포함된 새 노드
  • \draw두 루프 모두에 필수 연결 추가
  • 문제를 조기에 인식하고 해결하기 위해 작은 조치를 취하십시오.

제안하다다시 생각해 보면 여러 줄의 텍스트를 도입하는 것이 좋은 생각이라면. 가능하더라도 여러 스타일을 다시 조정해야 하거나 일부 접근 방식을 변경해야 할 수도 있습니다. 일반적으로: 적을수록 많음 - 많을수록 적음...

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}

관련 정보