5

The code that i have made for the following flow chart creates paths (arrows) which are shorter than the others. besides i don't know how to put the word department on top other box. here is my code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,arrows,calc,positioning}

\begin{document}

\tikzstyle{block} = [rectangle, draw, fill=white, node distance=2cm, text width=16em,  text centered, minimum height=4em, thick]



\tikzstyle{blks} = [rectangle, draw, fill=white, node distance=1.5cm, text width=6em,  text centered, minimum height=4em, dashed]


\tikzstyle{big} = [rectangle, draw, inner sep=0.5cm, thick]

\tikzstyle{line} = [draw, -latex',thick]

\begin{tikzpicture}[auto]
\node [block](exe) {\textbf{Executive}};
\node [block, below=of exe] (mgm) {\textbf{Departmental managers}};
\node [blks, below=of mgm] (fin) {Finance};
\node [blks, right=of fin] (prod) {Production};
 \node [blks, left=of fin] (resch) {Research};

\node [block, below=of fin] (sub) {\textbf{Sub-ordinate}};

\node [big,fit=(fin) (prod)(resch)] (dept) {\textbf{Departments}};

\path [line] (exe)--(mgm);
\path [line] (mgm) -- (dept);
\path [line] (resch)--(fin);
\path [line] (fin)--(prod);
\path [line] (dept) -- (sub); 


\end{tikzpicture}
\end{document}
2

This is an attempt. An extra node called A is added to form a new fit with fin, prod, resch

Also please see Should \tikzset or \tikzstyle be used to define TikZ styles?

enter image description here

Code

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{fit,arrows,calc,positioning}

\begin{document}

\tikzstyle{block} = [rectangle, draw, fill=white,text width=16em,  text centered, minimum height=4em, thick]

\tikzstyle{blks} = [rectangle, draw, fill=white, text width=6em,  text centered, minimum height=4em, dashed]

\tikzstyle{big} = [rectangle, draw, inner sep=0.5cm]

\tikzstyle{line} = [draw, -latex',thick]

\begin{tikzpicture}[auto]
\node [block](exe) {\textbf{Executive}};
\node [block, below=of exe] (mgm) {\textbf{Departmental managers}};
\node [blks, below=2cm of mgm] (fin) {Finance};
\node [blks, right=of fin] (prod) {Production};
\node [blks, left=of fin] (resch) {Research};

\node [block, below= 2cm of fin] (sub) {\textbf{Sub-ordinate}};
\node[above =0.2cm of  fin] (A) {\textbf{Department}};
\node [below = 0.3 of mgm, big,fit=(fin) (prod)(resch)(A), inner sep=0.5cm] (dept) {};

\path [line] (exe)--(mgm);
\path [line] (mgm) -- (dept);
\path [line] (resch)--(fin);
\path [line] (fin)--(prod);
\path [line] (dept) -- (sub); 

\end{tikzpicture}
\end{document}
  • please note the shifted (fin) to get the same arrow lengths – Harald Oct 27 '14 at 10:14
2

Jesse's answer is fine, I'll have some remarks and an alternative solution regarding the arrow length in this answer:

You set different node distances in block and blks which are ordered horizontally and vertically. You can have that in one setting for the whole picture:

\begin{tikzpicture}[node distance=2cm and 1.5cm]

The arrow length are different because the nodes are placed at equal distances but the arrows connect to different things (distance: mgmt to fin, arrow: mgmt to dept). This can be solved by placing the (dept) node first with an invisible border.

\node [block](exe) {\textbf{Executive}};
\node [block, below=of exe] (mgm) {\textbf{Departmental managers}};

\node[block, draw=none, below=of mgm] (deptlabel)   {\textbf{Departments}};

% place fin node right next to the label, the "inner sep" will keep the distance
\node [blks, below=0cm of deptlabel] (fin) {Finance};
\node [blks, right=of fin] (prod) {Production};
\node [blks, left=of fin] (resch) {Research};

Then for the box draw a vertically close fitting node (inner ysep = 0) and shift the (fin) node a bit to maintain the margin.

\node [big,inner ysep=0cm,fit={
    (prod)(resch) 
    (deptlabel) ([yshift=-0.5cm]fin.south) }] (dept) {};

rest as usual.

This approach will keep the globally set distances and inner separation intact, with the exception of the single yshift that would need to be adjusted if the other stuff changes.

Here the result and a version with some changes that indicates how it works.

1

We can also do this nicely using the Metapost library for drawing boxes (documented here).

enter image description here

I've used the image operator to do the boxes within a box.

prologues := 3;
outputtemplate := "%j%c.eps";
input boxes;
beginfig(1);

% extra space around the contents of the boxes 
defaultdx := 5mm;
defaultdy := 3mm;

% use Helvetica
defaultfont := "phvr8r";

% first make a picture of the departments
picture dep;
dep = image(
    boxit.res("Research");
    boxit.fin("Finance");
    boxit.prod("Production");
    (3cm,0) = prod.c - fin.c = fin.c - res.c;
    drawboxed(res,fin,prod);
    drawarrow res.e -- fin.w;
    drawarrow fin.e -- prod.w;
    label("Departments",fin.n + 9 up);
);

% now define four more boxes...
boxit.exec("Executive");
boxit.mgmt("Management");
boxit.dept(dep);
boxit.sub("Sub-ordinate");

% ... arranged vertically, 
(0,8mm) = exec.s-mgmt.n = mgmt.s-dept.n = dept.s-sub.n;

% ... and draw them plus connecting arrows
drawboxed(exec,mgmt,dept,sub);
drawarrow exec.s -- mgmt.n;
drawarrow mgmt.s -- dept.n;
drawarrow dept.s -- sub.n;

endfig;
end.

According to the manual linked above the syntax of boxit is

boxit.⟨suffix⟩(⟨picture expression⟩)

so I was expecting to be able to write boxit.sss(image(....)); but this produces errors with the bounding box macros in boxes.mp if the image contains other boxit instructions. It is not clear to me why this is the case, but using a temporary picture variable as the ⟨picture expression⟩ works fine.

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.