如何制作优秀的流程图

如何制作优秀的流程图

我使用了示例https://texample.net/tikz/examples/consort-flowchart/创建一个流程图。我遇到了一些问题,但看起来不错。

  1. 文本 1 - 形状必须向上移动,以免与箭头冲突。形状的宽度应与整个页面相同,文本应居中。我可以更改大小,但下面的其他形状也会向左移动。
  2. 其他箭头应从中间移动到下一个形状。

我该如何解决它?

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}
\centering  
  
  \begin{tikzpicture}[auto,
    block_top/.style ={rectangle, draw=black, thick, fill=white,
      text width=10em, text centered,
      minimum height=2em, inner sep=6pt},
    block_middle/.style ={rectangle, draw=black, thick, fill=white,
      text width=15em, text centered,
      minimum height=2em, inner sep=6pt},
    block_center/.style ={rectangle, draw=black, thick, fill=white,
      text width=8em, text centered,
      minimum height=4em},            
    block_left/.style ={rectangle, draw=black, thick, fill=white,
      text width=16em, text ragged, minimum height=4em, inner sep=6pt},
    block_lost/.style ={rectangle, draw=black, thick, fill=white,
      text width=16em, text ragged, minimum height=3em, inner sep=6pt},
      line/.style ={draw, thick, -latex', shorten >=0pt}]
    % outlining the flowchart using the PGF/TikZ matrix funtion
    
    \matrix [column sep=5mm,row sep=3mm] {
      % enrollment - row 1
      \node [block_top] (D) {TEXT 1};\\
      % enrollment - row 2
      \node [block_center] (DL) {TEXT 2}; 
      & \node [block_center] (DC) {TEXT 3};
      & \node [block_center] (DB) {TEXT 4};\\
      % follow-up - row 3
      \node [block_middle] (I) {TEXT 5}; 
      & \node [block_middle] (L) {TEXT 6}; \\
      % follow-up - row 4
      \node [block_center] (IG) {TEXT 7) }; 
      & \node [block_center] (IS) {TEXT 8)}; 
      & \node [block_center] (LS) {TEXT 9}; 
      & \node [block_center] (LO) {TEXT 10};\\
     };% end matrix
   
    % connecting nodes with paths
    \begin{scope}[every path/.style=line]
      \path (D) -| (DL);
      \path (D) -| (DC);
      \path (D) -| (DB);
      \path (DL) -- (I);
      \path (DB) -- (L);
      \path (DC) -- (L);
      \path (DC) -- (I);
      \path (DL) -- (I);
      \path (I)  -- (IG);
      \path (I)  -- (IS);
      \path (L)  -- (LS);
      \path (L)  -- (LO);
    \end{scope}
\end{tikzpicture}

\end{document}

干杯

答案1

我没有看到矩阵结构,而是节点级别取决于下方节点的位置。因此我从下往上开始。

  • 将底部的节点均匀分布。
  • 将上一行中的节点放置在其下一行的节点之间。
  • 将中心节点放置在第二行,位于下方节点和中心节点左侧和右侧节点之间的中间上方。
  • 将顶部节点定位在第二行的中心节点上方。

在此处输入图片描述

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows,calc}
\begin{document}
\begin{tikzpicture}[auto,
  block/.style={rectangle, draw=black, thick, fill=white,
      text width=#1, text centered,
      minimum height=2em, inner sep=6pt},
  block_top/.style = {block=40em},
  block_middle/.style = {block=15em},
  block_center/.style = {block=8em,minimum height=4em},
  block_left/.style ={block=16em,text ragged,minimum height=4em},
  block_lost/.style ={block=16em,text ragged,minimum height=3em},
  line/.style ={draw, thick, -latex', shorten >=0pt, rounded corners}
  ]
  % follow-up - row 4
  \node [block_center] (IG) {TEXT 7}; 
  \node [block_center,right=of IG] (IS) {TEXT 8}; 
  \node [block_center,right=of IS] (LS) {TEXT 9}; 
  \node [block_center,right=of LS] (LO) {TEXT 10};
  % follow-up - row 3
  \coordinate (IGIS) at ($(IG.north)!0.5!(IS.north)$);
  \node [block_middle,above=of IGIS] (I) {TEXT 5}; 
  \coordinate (LSLO) at ($(LS.north)!0.5!(LO.north)$);
  \node [block_middle,above=of LSLO] (L) {TEXT 6}; \\
  % enrollment - row 2
  \coordinate (IL) at ($(I.north)!0.5!(L.north)$);
  \node [block_center,above=of IL] (DC) {TEXT 3};
  \node [block_center] (DL) at (IG|-DC) {TEXT 2};
  \node [block_center] (DB) at (LO|-DC) {TEXT 4};
  % enrollment - row 1
  \node [block_top,above=of DC] (D) {TEXT 1};
  \begin{scope}[every path/.style=line]
    \path (D) -- +(0,-0.8) -| (DL);
    \path (D) -- (DC);
    \path (D) -- +(0,-0.8) -| (DB);
    \path (DL) -- (I);
    \path (DB) -- (L);
    \path (DC) -- (L);
    \path (DC) -- (I);
    \path (DL) -- (I);
    \path (I)  -- (IG);
    \path (I)  -- (IS);
    \path (L)  -- (LS);
    \path (L)  -- (LO);
  \end{scope}
\end{tikzpicture}

\end{document}

答案2

作为森林:

\documentclass[border=3.141592]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,
                shadows}

\begin{document}
    \begin{forest}
for tree = {
% nodes
    draw, semithick,
    fill=white,
    drop shadow,
    text width=6em,
    text badly centered,
% tree
       grow = south,
       edge = {-Straight Barb, semithick},
     anchor = north,
      forked edge, 
      l sep = 8mm,
   fork sep = 3.5mm,
where level = 2{s sep=2mm}{s sep=6mm},
% extry connection
/tikz/arr/.style = {draw=red, -Straight Barb, semithick},
            }% ed of "for tree"
 [ Text 1\\ (root)
    [Tex 2
        [Text 5, name=n12
            [Text 7]
            [Text 8]
        ]
    ]
    [Text 3, name=n21
        [Text 6, name=n22
            [Text 9]
            [Text 10]
        ]
    ]
    [Tex 4, name=n31]
 ]
\draw[arr] ([xshift=-1em] n21.south) -- ++ (0,-3.5mm) -| ([xshift=1em] n12.north);
\draw[arr]  (n31.south) -- ++ (0,-3.5mm) -| ([xshift=1em] n22.north);       
    \end{forest}
\end{document}

在此处输入图片描述

相关内容