tikz-图表问题

tikz-图表问题

首先,我要感谢你们为这个论坛提供的帮助。这是我在这里的第一篇帖子,所以如果我可以改进某些地方,请告诉我,以便日后改进 :)

我在使用 tikz 时遇到了一些问题,希望您能帮助我。最终结果应如下所示:

在此处输入图片描述

我不知道如何调整这些框的大小,使它们具有相同的大小。我的意思是这三个框的宽度应该与顶部框的宽度相同。到目前为止,我所拥有的:

    \documentclass{standalone}
\usepackage{tikz}
  \usetikzlibrary{shapes,arrows,fit,calc,positioning}
  \tikzset{box/.style={draw, rectangle, thick, text centered, minimum height=3em}}
  \tikzset{line/.style={draw, thick, -latex'}}
\begin{document}


\begin{tikzpicture}[auto]
    \node [box]                                     (inv)      {0};
    \node [box, below=0.5cm of inv]                 (deter)    {1};
    \coordinate [below=0.5cm of deter]              (vuoto1)   {};
    \node [box, below=0.5cm of vuoto1]              (meth2)    {2};
    \node [box, left=0.5cm of meth2]                (meth1)    {3};
    \node [box, right=0.5cm of meth2]               (meth3)    {4};   
    \node [box, below=0.5cm of meth1]               (select)   {5};
    \node [box, below=0.5cm of select]              (select2)  {6}; 
    \node [box, below=4.5cm of meth2]               (decide)   {7};
    \node [box, below=0.5cm of decide]              (inter)    {8};

    \path [line] (inv)      --    (deter);
    \path [line] (deter)    --    (vuoto1);
    \path [line] (vuoto1)   -|    (meth1);
    \path [line] (vuoto1)   -|    (meth2);
    \path [line] (vuoto1)   -|    (meth3);
    \path [line] (meth1)    --    (select);
    \path [line] (select)   --    (select2);
    \path [line] (select2)  --    (decide);
    \path [line] (meth2)    --    (decide);
    \path [line] (meth3)    --    (decide);
    \path [line] (decide)    --    (inter);
\end{tikzpicture}
\end{document}

正如您所见,框的宽度仅与文本内容一样。

如果你能帮助我我将非常感激:)

多谢。

克里斯汀

答案1

这是一种“间接”方法,其中最宽节点的边框是单独绘制的。我draw,thickbox样式中删除了,并将它们添加到新样式中narrowbox,其中包括box样式和text width=4cm。这用于中心的五个节点。

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\tikzset{
  box/.style={rectangle, text centered, minimum height=3em},
  narrowbox/.style={box,text width=4cm,draw,thick},
  line/.style={draw, thick, -Stealth}
}
\begin{document}
\begin{tikzpicture}[auto]
    \node [box]                                     (inv)      {Determinate the clustering variables};
    \node [box, below=0.5cm of inv]                 (deter)    {Decide the clustering procedure};
    \coordinate [below=0.5cm of deter]              (vuoto1);
    \node [narrowbox, below=0.5cm of vuoto1]        (meth2)    {Partitioning clustering};
    \node [narrowbox, left=0.5cm of meth2]          (meth1)    {Hierarchical clustering};
    \node [narrowbox, right=0.5cm of meth2]         (meth3)    {Graph-based clustering};   
    \node [narrowbox, below=0.5cm of meth1]         (select)   {Select a measure of similarity or dissimilarity};
    \node [narrowbox, below=0.5cm of select]        (select2)  {Choose a clustering algorithm}; 
    \node [box, below=4.5cm of meth2]               (decide)   {Decide the clustering procedure};
    \node [box, below=0.5cm of decide]              (inter)    {Decide the clustering procedure};

    \path [line] (inv)      --    (deter);
    \path [line] (deter)    --    (meth2);
    \path [line] (vuoto1)   -|    (meth1);
    \path [line] (vuoto1)   -|    (meth3);
    \path [line] (meth1)    --    (select);
    \path [line] (select)   --    (select2);
    \path [line] (select2)  --    (select.south |- decide.north);
    \path [line] (meth2)    --    (decide);
    \path [line] (meth3)    --    (meth3.south |- decide.north);
    \path [line] (decide)   --    (inter);

% draw rectangles around top and bottom nodes
\foreach \N in {inv,deter,decide,inter}
   \draw [thick] (\N.north -| meth1.west) rectangle (\N.south -| meth3.east);
\end{tikzpicture}
\end{document}

相关内容