4

first of all I would like to thank you for this helpful forum. This is my first post here so if I can improve something, just tell it to me for the future :)

I have some troubles with tikz and hope you can help me. The final result should looks like this:

enter image description here

I dont know how to resize the boxes that they have the same size. I mean the three boxes should be as width as the top boxes. What I have so far:

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

As you can seen the boxes are only as width as the text content.

I would appreciate if you can help me :)

Thanks a lot.

Christine

  • Great first question. Welcome to TeX.SE! – Richard Jun 28 '16 at 23:24
5

Here is an "indirect" approach, where the borders of the widest nodes are drawn separately. I removed draw,thick from the box style, and added them to a new style narrowbox, which include the box style and text width=4cm. This is used for the five nodes in the center.

enter image description here

\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}
  • 1
    Hi Torbjørn, thank you so much for your help. Finally it works! Many thanks. – Christine Jun 28 '16 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.