我怎样才能在 LaTeX 中创建这种类型的图表?

我怎样才能在 LaTeX 中创建这种类型的图表?

我想在 LaTeX 中重新创建下图:

在此处输入图片描述

使用的东西蒂克兹可能会很好,我已经看到TikZ的UML这和我想要的有点相似,但我真的很需要一些指导。我不确定如何在 TikZ 中创建这样的图表。感谢您提供的任何想法。

答案1

这可以给你一个起点:

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,backgrounds,calc}

\pgfdeclarelayer{backgroundi}
\pgfdeclarelayer{backgroundii}
\pgfdeclarelayer{backgroundiii}
\pgfsetlayers{backgroundiii,backgroundii,backgroundi,main}

\begin{document}

\begin{tikzpicture}[node distance=0.3cm,
mynode/.style={
  draw,
  fill=white,
  text width=3cm,
  align=center,
  minimum height=20pt
},
>=latex
]

% The upper "Job" box
\node[mynode] (func) {function}; 
\node[mynode,below=of func] (argu) {arguments}; 
\node[mynode,below=of argu] (time) {timeout}; 
\node[mynode,below=of time] (resu) {result}; 
\node[mynode,below=of resu] (other) {other information};

% Auxiliary coordinates for the background frame for "Job"
\coordinate (ul) at ([xshift=-15pt,yshift=7pt]func.north west);
\coordinate (lr) at ([xshift=15pt,yshift=-7pt]other.south east);

% The background frame for "Job"
\begin{pgfonlayer}{backgroundi}
\node[draw,fill=gray!30,fit=(ul) (lr)] (frame) {}; 
\end{pgfonlayer}
\node[anchor=south west,draw,fill=gray!30] 
  at ([yshift=-.5\pgflinewidth]frame.north west) {Job};

% The lower "Job" box
\node[mynode,below=2cm of frame.south] (funcb) {function}; 
\node[mynode,below=of funcb] (argub) {arguments}; 
\node[mynode,below=of argub] (timeb) {timeout}; 
\node[mynode,below=of timeb] (resub) {result}; 
\node[mynode,below=of resub] (otherb) {other information};

% Auxiliary coordinates for the background frame for "Job"
\coordinate (ulb) at ([xshift=-15pt,yshift=7pt]funcb.north west);
\coordinate (lrb) at ([xshift=15pt,yshift=-7pt]otherb.south east);

% The background frame for "Job"
\begin{pgfonlayer}{backgroundi}
\node[draw,fill=gray!30,fit=(ulb) (lrb)] (frameb) {}; 
\end{pgfonlayer}
\node[anchor=south west,draw,fill=gray!30] 
  at ([yshift=-.5\pgflinewidth]frameb.north west) {Job};

% Auxiliary coordinates for the background frame for both "Job" boxes
\coordinate (ulc) at ([xshift=-15pt,yshift=18pt]frame.north west);
\coordinate (lrc) at ([xshift=15pt,yshift=-7pt]frameb.south east);

% The background frame for both "Job" boxes
\begin{pgfonlayer}{backgroundii}
\node[draw,fill=gray!50,fit=(ulc) (lrc)] (framec) {}; 
\end{pgfonlayer}
\node[anchor=south west,draw,fill=gray!50] 
  at ([yshift=-.5\pgflinewidth]framec.north west) {Job group};

% The midlle "init" box
\node[mynode,right=3.5cm of func] (init) {init}; 
\node[mynode,below=of init] (subm) {submit}; 
\node[mynode,below=of subm] (getR) {getResults}; 

% The "pool" box
\node[mynode,right=2cm of init] (processi) {process}; 
\node[mynode,below=of processi] (processii) {process}; 
\node[mynode,below=of processii] (processiii) {process}; 
\node[mynode,below=of processiii] (processiv) {process}; 

% Auxiliary coordinates for the background frame for "pool" box
\coordinate (uld) at ([xshift=-15pt,yshift=7pt]processi.north west);
\coordinate (lrd) at ([xshift=15pt,yshift=-7pt]processiv.south east);

% The background frame for "pool"
\begin{pgfonlayer}{backgroundi}
\node[draw,fill=gray!30,fit=(uld) (lrd)] (framed) {}; 
\end{pgfonlayer}
\node[anchor=south west,draw,fill=gray!30] 
  at ([yshift=-.5\pgflinewidth]framed.north west) {pool};

% Auxiliary coordinates for the background frame for both "init" and "pool" boxes
\coordinate (ule) at ([yshift=17pt,xshift=-15pt]init.north west|-framed.north);
\coordinate (lre) at ([xshift=15pt,yshift=-7pt]framed.south east);

% The background frame for "init" and "pool"
\begin{pgfonlayer}{backgroundii}
\node[draw,fill=gray!50,fit=(ule) (lre)] (framee) {}; 
\end{pgfonlayer}
\node[anchor=south west,draw,fill=gray!50] 
  at ([yshift=-.5\pgflinewidth]framee.north west) {ParallelJobProcessor};

% Auxiliary coordinates for the general background frame
\coordinate (ulf) at ([yshift=17pt,xshift=-15pt]framec.north west);
\coordinate (lrf) at ([xshift=15pt,yshift=-7pt]framee.south east|-framec.south);

% The general background frame
\begin{pgfonlayer}{backgroundiii}
\node[draw,fill=black!60,fit=(ulf) (lrf)] (framef) {}; 
\end{pgfonlayer}

% Some arrows
\begin{scope}[line width=6pt]
\draw[->] 
  (frame.east|-argu) -- (subm);
\draw[->] 
  (getR.west) -- +(-1.5cm,0) -| ([xshift=2cm]resub.east) -- (resub.east);
\draw[->]
  (init.east) -- (framed.west|-processi.west);
\draw[->]
  (subm.east) -- (framed.west|-processii.west);
\draw[->]
  (framed.west|-processiii.west) -- (getR.east);
\end{scope}
\end{tikzpicture}%

\end{document}

在此处输入图片描述

答案2

在 TikZ 中执行此操作的最简单方法是通过提供坐标并手动放置节点来手动放置框。这是最简单但这种方法有很多缺点,比如如果你想事后改变它,那么你可能不得不改变所有的坐标。如果这是最终的图像,而你不打算做任何改变,那么你应该使用这种方法。

相关内容