流程图绘制

流程图绘制

我为以下流程图编写的代码创建的路径(箭头)比其他路径短。此外,我不知道如何将单词“department”放在其他框的顶部。这是我的代码

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

答案1

这是一次尝试。添加了一个称为的额外节点A,以形成新的拟合fin, prod, resch

另请参阅应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?

在此处输入图片描述

代码

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

答案2

杰西的回答很好,我会在这个答案中对箭头长度提出一些意见和替代解决方案:

block您可以在和中设置不同的节点距离,blks这些节点按水平和垂直顺序排列。您可以在一个设置中为整个画面设置这些:

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

箭头长度不同是因为节点的距离相等,但箭头连接到不同的东西(距离:mgmt 到 fin,箭头:mgmt 到 dept)。这可以通过首先放置 (dept) 节点并使用不可见的边框来解决。

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

然后为框绘制一个垂直紧密贴合的节点(inner ysep = 0),并稍微移动(鳍)节点以保持边缘。

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

照常休息。

yshift这种方法将保持全局设置的距离和内部分离不变,但如果其他内容发生变化,则需要调整单个距离。

这里是结果和经过一些更改的版本,表明了它的工作原理。

答案3

我们也可以使用元帖子绘制方框的库(记录这里)。

在此处输入图片描述

我已经使用image运算符来处理盒子内的盒子。

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.

根据上面链接的手册,语法boxit

boxit.⟨suffix⟩(⟨picture expression⟩)

所以我原本以为可以写入,但如果图像包含其他指令boxit.sss(image(....));,这会导致边界框宏出错。我不清楚为什么会出现这种情况,但使用临时图片变量作为工作正常。boxes.mpboxit⟨picture expression⟩

相关内容