更新

更新

嗨,我是 TikZ 软件包的新手(所以如果这是一个简单的问题,我很抱歉),我在格式化方面遇到了麻烦。以下是我目前遇到的问题:

    \documentclass{article}
    \usepackage[latin1]{inputenc}
    \usepackage{tikz}
    \usetikzlibrary{shapes,arrows}
    \usepackage{caption}

    \begin{document}

      \sffamily
      \footnotesize
      \begin{tikzpicture}[auto,
       block_full/.style ={rectangle, draw=black, thick, fill=white,
          text width=20em, text ragged, minimum height=4em, inner sep=6pt},
        block_left/.style ={rectangle, draw=black, thick, fill=white,
          text width=20em, text ragged, minimum height=4em, inner sep=6pt},
        block_noborder/.style ={rectangle, draw=none, thick, fill=none,
          text width=18em, text centered, minimum height=1em},
        block_assign/.style ={rectangle, draw=black, thick, fill=white,
          text width=12em, text centered, minimum height=3em, inner sep=6pt},
          line/.style ={draw, very thin, -latex', shorten >=0pt}]
        % outlining the flowchart using the PGF/TikZ matrix funtion

             \matrix [column sep=3mm,row sep=3mm] {
          % row 1
          \node [block_full] (presub) {Pre-Submission:\\ 
            -  \\
            -  \\
            - }; \\

          %  row 2
          \node [block_noborder] (input) {Input data};\\

          % row 3
          \node [block_full] (routine) {Routine Checks:\\ 
            -  \\
           -   };  \\

          %  row 4
                \node [block_noborder] (bad1) {Bad result}; 

          &  \node [block_noborder] (good1) {Good result}; \\

          % row 5
          \node [block_left] (influence) {Influence: \\
            -  \\
            -  \\ }; &      \\

          % row 6
          \node [block_left] (inliers) {Inliers:\\ 
          -  \\
          -  \\ }; &      \\

          % row 7
          \node [block_left] (multiple) {Multiple: \\
          -  \\
          -  \\ }; &      \\

          % row 8
          \node [block_left] (cat) {Categorical Variables:\\ 
            -  \\
            -  \\  }; &    \\

          %  row 9
          \node [block_noborder] (bad2) {Bad Result};
          & ;     \node [block_noborder] (good2) {Good Result}; \\                

         % row 10
             \node [block_left] (digit) {Digits:\\ 
            -  \\
            -  \\  }; &    \\

        % row 11
           \node [block_assign] (concludeyes) {Conclude yes};
          & \node [block_assign] (concludeno) {Conclude no}; \\
        };% end matrix
      \end{tikzpicture}
    \end{document}

输出如下内容: 在此处输入图片描述

我还没有添加路径,但我想知道是否有办法扩大前两个框的中心,但保留常规框下方的两个列分支?

为了清晰起见,我绘制了一张我设想的最终图表的小图。 在此处输入图片描述

答案1

像你这样使用矩阵有点棘手。你可以在希望“大框”出现的行上放置两个大小合适但没有内容的“辅助”节点,然后使用fit库创建一个适合这些辅助节点的节点。我觉得这个解决方案有点笨拙。

相反,我建议采用不同的方法。不要使用矩阵,因为矩阵的结构僵化,不太适合此图,而是positioning使用库来指定每个框相对于其他先前绘制的框的位置。

这是我的代码:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\usepackage{caption}

\begin{document}

\tikzset{
   block_full/.style ={rectangle, draw=black, thick, fill=white,
      text width=20em, text ragged, minimum height=4em, inner sep=6pt},
    block_left/.style ={rectangle, draw=black, thick, fill=white,
      text width=20em, text ragged, minimum height=4em, inner sep=6pt},
    block_noborder/.style ={rectangle, draw=none, thick, fill=none,
      text width=20em, text centered, minimum height=1em, inner sep=6pt},
    block_assign/.style ={rectangle, draw=black, thick, fill=white,
      text width=12em, text centered, minimum height=3em, inner sep=6pt},
      line/.style ={draw, very thin, -latex', shorten >=0pt},
}

\sffamily
\footnotesize
\begin{tikzpicture}[node distance=3mm]
  \node [block_full, text width=40em] (presub) {
    Pre-Submission:\\ 
    -  \\
    -  \\
    - }; 

  \node [block_noborder, below=of presub] (input) {Input data};

  \node [block_full, text width=40em, below=of input] (routine) {
    Routine Checks:\\ 
    -  \\
    - }; 

  \node [block_noborder, below=of routine.south west, anchor=north west] (bad1) {Bad result}; 
  \node [block_noborder, below=of routine.south east, anchor=north east] (good1) {Good result};

  \node [block_left, below=of bad1.south west, anchor=north west] (influence) {
    Influence: \\
    -  \\
    -  \\ }; 

  \node [block_left, below=of influence] (inliers) {
    Inliers:\\ 
    -  \\
    -  \\ }; 

  \node [block_left, below=of inliers] (multiple) {
    Multiple: \\
    -  \\
    -  \\ };

  \node [block_left, below=of multiple] (cat) {
    Categorical Variables:\\ 
    -  \\
    -  \\  };

  \node [block_noborder, below=of cat] (bad2) {Bad Result};
  \node [block_noborder] at (bad2-|good1) (good2) {Good Result}; 

  \node [block_left, below=of bad2] (digit) {
    Digits:\\ 
    -  \\
    -  \\  };

  \node [block_assign, below=of digit] (concludeyes) {Conclude yes};
  \node [block_assign ] at (concludeyes-|good2)(concludeno) {Conclude no};
\end{tikzpicture}
\end{document}

结果如下:

结果

请注意,对于某些节点(good2和),我没有使用语法(即等)concludeno来指定位置;而是使用了非常方便的语法,即“在通过的水平线和通过的垂直线的交点处”。positioningbelow=of...at (foo-|bar)foobar

更新

我添加了连接:

  \draw[->] (presub) -- (input);
  \draw[->] (input) -- (routine);
  \draw[->] (routine.south-|bad1) -- (bad1);
  \draw[->] (routine.south-|good1) -- (good1);
  \xdef\prevnode{bad1}
  \foreach \n in {influence, inliers, multiple, cat, bad2, digit, concludeyes} {
      \draw[->] (\prevnode) -- (\n);
      \xdef\prevnode{\n}
  }
  \draw[->] (cat) -| (good2);
  \draw[->] (good2) -- (concludeno);

结果

答案2

我倾向于把它画成一棵树。这意味着只需要手工添加一条连接线,如果你愿意的话,你可以让连接变得更漂亮一些。

此代码使用forest。请注意,我更改了块节点的填充,只是为了跟踪我正在做的事情。(fill=white当背景为白色时很难看清!)

请注意,该arrows库已弃用。tikz有关详细信息,请参阅手册。

\documentclass{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}

\begin{document}

 \sffamily
 \footnotesize

\pgfkeys{/forest,
   noborder/.append style={draw=none, fill=none, text width=18em, text centered, minimum height=1em, align=center},
   assign/.append style={align=center, minimum height=3em, inner sep=6pt},
   full/.append style={text width=35em},
}
\begin{forest}
 for tree={
   font=\sffamily\footnotesize,
   draw,
   thick,
   fill=blue!10,
   align=left,
   text width=20em,
   minimum height=4em,
   inner sep=6pt,
   edge path={
     \noexpand\path[very thin, -{Latex[]}, \forestoption{edge}]
      (!u.parent anchor) -- +(0,-5pt) -| (.child anchor)\forestoption{edge label};
    },
   child anchor=north,
   parent anchor=south,
   l sep+=5pt,
 }
 [{Pre-Submission:\\---\\---\\---}, name=presub, full
   [Input Data, name=input, full, noborder
     [{Routine Checks:\\---\\---}, name=routine, full
       [Bad Result, name=bad1, noborder
         [{Influence:\\---\\---}, name=influence
           [{Inliers:\\---\\---}, name=inliers
             [{Multiple:\\---\\---}, name=multiple
                [{Categorical Variables:\\---\\---}, name=cat
                  [Bad Result, name=bad2, noborder, tier=result2
                    [{Digits:\\--\\--}, name=digit
                      [Conclude Yes, name=concludeyes, assign, tier=conclude]
                    ]
                  ]
               ]
             ]
           ]
         ]
       ]
       [Good Result, name=good1, noborder
          [,phantom%
            [Good Result, name=good2, noborder, tier=result2
              [Conclude No, name=concludeno, assign, tier=conclude]
            ]
          ]
       ]
     ]
   ]
 ]
 \draw [very thin, -{Latex[]}] (cat.east) -| (good2.north);
\end{forest}

\end{document}

树状图

相关内容