![简单图表的可视化后端](https://linux22.com/image/240022/%E7%AE%80%E5%8D%95%E5%9B%BE%E8%A1%A8%E7%9A%84%E5%8F%AF%E8%A7%86%E5%8C%96%E5%90%8E%E7%AB%AF.png)
答案1
绘制此类图表的一种方法是使用节点定位。这是一个您可以尝试的版本。
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[every node/.style={align=center,minimum width=4cm,minimum height=2cm,rectangle,outer sep=0pt},>=latex,
decoration={
markings,% switch on markings
mark=at position 0.25 with {\draw (-4pt,-4pt) -- (4pt,4pt);\draw (4pt,-4pt) -- (-4pt,4pt);}}
]
\node (empty) {};
\node[below=of empty] (mech-1) {mechanism\\descriptor};
\node[below=of mech-1] (mech-2) {mechanism\\descriptor};
\node[right=of empty] (event) {\textbf{event}\\caption};
\node[draw,right=of mech-1] (process-1-1) {\textbf{process}\\caption};
\node[draw,right=of process-1-1] (process-1-2) {\textbf{process}\\caption};
\node[draw,right=3cm of mech-2] (process-2-1) {\textbf{intermediate process}};
\node[draw,right=of process-2-1] (process-2-2) {\textbf{intermediate process}};
\node[below=of process-2-1] (failure) {\textbf{failure}};
\node[below=of process-2-2] (success) {\textbf{success}};
\draw[->] (event) -- (process-1-1);
\draw[->] (process-1-1.south) -- (process-2-1.north);
\draw[->] (process-2-1.north) -- (process-1-2.south);
\draw[->] (process-1-2.south) -- (process-2-2.north);
\draw[postaction={decorate}] (process-2-1) -- (failure);
\draw[->] (process-2-2) -- (success);
\end{tikzpicture}
\end{document}
结果是
答案2
答案3
下面是另一个结合了 Frédérik 对该positioning
库的使用和 Greg 对该chains
库与其他几个库一起使用的建议(以纯格式):
\font\ss=cmss9
\font\ssbf=cmssbx10 at 9pt
\font\ssit=cmssi9
\let\tenbf\ssbf
\let\tenit\ssit
\input tikz
\usetikzlibrary{
chains, % for the "start chain", "on chain", and "join" [manual section 28, p. 284]
arrows, % for the ">=triangle 45" [manual section 23, p. 256-]
positioning, % for the "left=<optional dimen> of ...",
% and "below left=<optional dimen(s)> of ..."
% [manual section 5.2, p. 62-]
decorations.markings, % for the "X" on a join [manual p. 327-]
shapes.multipart % for the "rectangle split" styles [manual p. 450-453]
}
\tikzpicture[
font=\ss,
node distance=1.5cm and -1cm, % the y distance and x distance of nodes
% ^the x distance is set to a negative value to reserve space
every node/.style={minimum width=3cm,align=center},
every on chain/.style=join,
every join/.style={->,thick,>=triangle 45},
mynode/.style={
on chain=going #1,
% ^you can give parameters to your styles, so that for example:
% node[mynode=below] expands to: node[on chain=going below]
inner xsep=1em,
rectangle split,rectangle split parts=2,
rectangle split ignore empty parts=true,
rectangle split draw splits=false,
every text node part/.style={font=\bf}},
myfail/.style={thick,-,postaction={decorate,decoration={markings,
% I have a feeling this could be accomplished more easily
mark=at position .25 with { \draw (-3pt,-3pt) -- (3pt,3pt)
(3pt,-3pt) -- (-3pt,3pt); }}}}
]
\def\npt{\nodepart{two}} % just a local definition to save typing
\draw[start chain]
node[mynode] {event\npt caption}
node[draw,mynode=below] (proc-1) {process\npt caption}
node[draw,mynode=below right] {intermediary process}
{[start branch,every join/.style=myfail]
node[mynode=below] {failure\npt caption}}
node[draw,mynode=above right] {process\npt caption}
node[draw,mynode=below right] {intermediary process}
node[mynode=below] {success\npt caption};
\draw[every node/.append style={align=left,font=\it}]
node[left=1cm of proc-1] (desc-1) {mechanism\\descriptor}
% ^without the "1cm", the node would've been -1cm left of proc-1
% because of the "node distance" definition for the whole tikzpicture
node[below=of desc-1] {mechanism\\descriptor};
\endtikzpicture
\bye
好像: