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

d3pd 01/23/2014. 2 answers, 740 views
tikz-pgf diagrams tikz-uml

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

在此处输入图像描述

使用TikZ的东西可能很好,我看过TikZ-UML有点类似于我的想法,但我真的很重视一些指导。 我不知道如何在TikZ中创建这样的图表。 感谢您提出的任何想法。

3 Comments
3 cfr 01/23/2014
发布复杂的图形并期望人们为您创建它并不是很合理。 如果您发布一些代码表明您已经离开并询问有关您遇到的特定问题的建议,那么您更有可能获得帮助。 MWE,即使是效果不佳的MWE,也能为人们提供一些工作。
2 d3pd 01/23/2014
哦,天哪。 我不希望有人为我创造它! 这不公平。 简单地说,制作一个像我所知的图表的方法似乎是一项大量的工作,我想看看是否有人可以指导我的方法(比如推荐替代TikZ-UML)。 如果另一种方法可以用更少的努力做同样的事情,我只是不想付出很大的努力。 有没有更好的方式来提问?
cfr 01/23/2014
不,我认为你对这个评论没问题。 人们会看到并给你起点(就像他们一样)。 否则我会建议明确说明你正在寻找一个开始,而不是有人为你做这一切。 唯一的原因是人们发布图片并等待完全开发的解决方案并不罕见。 由于这不是非常公平,明确你(非常合理)的期望会鼓励人们有所回应。 我很高兴看到你现在至少有一个有用的起点!

2 Answers


Gonzalo Medina 01/23/2014.

这可以给你一个起点:

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

在此处输入图像描述

1 comments
d3pd 01/23/2014
哇! 那很快。 图层和辅助坐标是我以前从未见过的技巧。 它们使得相对容易地将帧定位在节点周围以用于功能等。 这是非常有帮助的。 非常感谢您的帮助! :d

Kartik 01/23/2014.

在TikZ中执行此操作的最简单方法是通过提供坐标并手动放置节点来手动放置框。 这是easiest and simplesteasiest and simplest但这种方法有许多缺点,比如如果你想在之后改变它,那么你可能需要改变所有坐标。 如果这是最终图像,并且您不打算进行任何更改,那么您应该使用此方法。

1 comments
1 d3pd 01/23/2014
是的,我认为你对节点方法最简单易懂是对的。 Gonzalo Medina所展示的框架方法可以减轻很多事情的难度,例如,以概念上简单的方式重新定位某些东西。 谢谢你的想法。

HighResolutionMusic.com - Download Hi-Res Songs

1 Alan Walker

Diamond Heart flac

Alan Walker. 2018. Writer: Alan Walker;Sophia Somajo;Mood Melodies;James Njie;Thomas Troelsen;Kristoffer Haugan;Edvard Normann;Anders Froen;Gunnar Greve;Yann Bargain;Victor Verpillat;Fredrik Borch Olsen.
2 Sia

I'm Still Here flac

Sia. 2018. Writer: Sia.
3 Little Mix

Woman Like Me flac

Little Mix. 2018. Writer: Nicki Minaj;Steve Mac;Ed Sheeran;Jess Glynne.
4 Cardi B

Taki Taki flac

Cardi B. 2018. Writer: Bava;Juan Vasquez;Vicente Saavedra;Jordan Thorpe;DJ Snake;Ozuna;Cardi B;Selena Gomez.
5 Eminem

Venom flac

Eminem. 2018. Writer: Eminem.
6 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
7 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.
8 Kelsea Ballerini

This Feeling flac

Kelsea Ballerini. 2018. Writer: Andrew Taggart;Alex Pall;Emily Warren.
9 Bradley Cooper

Shallow flac

Bradley Cooper. 2018. Writer: Andrew Wyatt;Anthony Rossomando;Mark Ronson;Lady Gaga.
10 Dewain Whitmore

Burn Out flac

Dewain Whitmore. 2018. Writer: Dewain Whitmore;Ilsey Juber;Emilio Behr;Martijn Garritsen.
11 Mako

Rise flac

Mako. 2018. Writer: Riot Music Team;Mako;Justin Tranter.
12 Bradley Cooper

Always Remember Us This Way flac

Bradley Cooper. 2018. Writer: Lady Gaga;Dave Cobb.
13 Lukas Graham

Love Someone flac

Lukas Graham. 2018. Writer: Don Stefano;Morten "Rissi" Ristorp;Morten "Pilo" Pilegaard;Jaramye Daniels;James Alan;David LaBrel;Lukas Forchhammer Graham.
14 Avril Lavigne

Head Above Water flac

Avril Lavigne. 2018. Writer: Stephan Moccio;Travis Clark;Avril Lavigne.
15 Deep Chills

Run Free flac

Deep Chills. 2018.
16 Khalid

Better flac

Khalid. 2018. Writer: Charlie Handsome;Jamil Chammas;Denis Kosiak;Tor Erik Hermansen;Mikkel Stoleer Eriksen;Khalid.
17 Charli XCX

1999 flac

Charli XCX. 2018. Writer: Charli XCX;Troye Sivan;Leland;Oscar Holter;Noonie Bao.
18 NCT 127

Regular (English Version) flac

NCT 127. 2018.
19 Camila Cabello

Consequences (Orchestra) flac

Camila Cabello. 2018. Writer: Emily Lynn Weisband;Nicolle Galyon;Amy Wadge;Bart Schoudel;Frank Dukes;Camila Cabello.
20 Lady Gaga

Look What I Found flac

Lady Gaga. 2018. Writer: DJ White Shadow;Nick Monson;Mark Nilan Jr;Lady Gaga.

Related questions

Hot questions

Language

Popular Tags