现在我只能使用此代码生成蓝色和绿色的框
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.arrows}
\usetikzlibrary{automata} % LATEX and plain TEX
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds, chains,positioning,fit,petri,matrix,shapes.arrows,shadows,backgrounds}
\usetikzlibrary{mindmap}
\usetikzlibrary{shapes,arrows,fit,calc,shadings,graphs}
\tikzset{box/.style={draw, rectangle, rounded corners, thick,node distance=7em, text width=6em, text centered , inimum height=3.5em}}
\tikzset{container/.style={draw, rectangle , dashed, inner sep=2em}}
\tikzset{line/.style={draw, thick, -latex '}}
%Disegno per i grafici TikZ
\definecolor{bluei}{RGB}{83,116,191}
\definecolor{blueii}{RGB}{207,212,232}
\definecolor{greeni}{RGB}{135,200,81}
\definecolor{greenii}{RGB}{216,235,207}
\tikzset{
myiblock/.style 2 args={
draw=white,
fill=#1,
line width=1pt,
rounded corners,
minimum height=1cm,
align=center,
text=white,
font=\sffamily,
text width=#2
},
myoblock/.style={
fill=#1,
rounded corners,
align=center,
inner xsep=10pt
}
}
\begin{document}
%1chain
\begin{tikzpicture}[node distance=3pt and 1cm]
\node[myiblock={bluei}{2cm}]
(info1)
{Id1 long 7 chars};
\node[myiblock={bluei}{2cm},below=of info1]
(info2)
{Id2 long 7 chars};
\node[myiblock={bluei}{2cm},below=of info2]
(info3)
{Id3 long 7 chars};
\node[myiblock={bluei}{2cm},below=of info3]
(info4)
{Id4 long 7 chars};
\node[myiblock={bluei}{2cm},below=of info4]
(info5)
{Id5 long 7 chars};
\node[myiblock={bluei}{2cm},below=of info5]
(info6)
{Id6 long 7 chars};
\node[myiblock={bluei}{2cm},below=of info6]
(info7)
{Id7 long 7 chars};
\begin{pgfonlayer}{background}
\end{pgfonlayer}
%2 chain
\begin{scope}[xshift=6cm,node distance=3pt and 1cm]
\node[myiblock={greeni}{4cm}]
(infoob1)
{Text1 long 34 chars};
\node[myiblock={greeni}{4cm},below=of infoob1]
(infoob2)
{Text2 long 34 chars};
\node[myiblock={greeni}{4cm},below=of infoob2]
(infoob3)
{Text3 long 34 chars};
\node[myiblock={greeni}{4cm},below=of infoob3]
(infoob4)
{Text4 long 34 chars};
\node[myiblock={greeni}{4cm},below=of infoob4]
(infoob5)
{Text5 long 34 chars};
\node[myiblock={greeni}{4cm},below=of infoob5]
(infoob6)
{Text6 long 34 chars};
\node[myiblock={greeni}{4cm},below=of infoob6]
(infoob7)
{Text7 long 34 chars};
\begin{pgfonlayer}{background}
\end{pgfonlayer}
\end{scope}
\end{tikzpicture}
%3 chain
\begin{tikzpicture}[node distance=3pt and 1cm]
\node[myiblock={bluei}{2cm}]
(info1)
{Label1 long 20 chars};
\node[myiblock={bluei}{2cm},below=of info1]
(info2)
{Label2 long 20 chars};
\node[myiblock={bluei}{2cm},below=of info2]
(info3)
{Label3 long 20 chars};
\node[myiblock={bluei}{2cm},below=of info3]
(info4)
{Label4 long 20 chars};
\node[myiblock={bluei}{2cm},below=of info4]
(info5)
{Label5 long 20 chars};
\node[myiblock={bluei}{2cm},below=of info5]
(info6)
{Label6 long 20 chars};
\node[myiblock={bluei}{2cm},below=of info6]
(info7)
{Label7 long 20 chars};
\begin{pgfonlayer}{background}
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
我的问题是: 1. 如何添加另一个框 2. 如何在框之间添加...(参见第一个链) 3. 如何保持原始图像的相同框大小?
先谢谢了
答案1
看看,这是否是你在寻找的:
\documentclass[border=10pt,tikz]{standalone}
\usetikzlibrary{arrows.meta,
calc, chains,
decorations.pathreplacing,
positioning}
%Disegno per i grafici TikZ
\definecolor{bluei}{RGB}{83,116,191}
\definecolor{greeni}{RGB}{135,200,81}
\begin{document}
\begin{tikzpicture}[
node distance = 6mm and 66mm,
start chain = going below,
auto,
iblock/.style = {draw=none,
fill=bluei,
rounded corners,
minimum height=1cm,
align=center,
text width=#1,
text=white, font=\sffamily,
inner xsep=10pt,
on chain},
oblock/.style = {draw=none,
fill=greeni,
rounded corners,
inner xsep=10pt, outer sep=1mm,
text width=40mm},
line/.style = {draw=bluei, line width=1mm,
shorten >=1mm, shorten <=1mm,
-{Triangle[fill=bluei]}}
]
%1chain
\node[iblock=1.2cm] (info11) {Id1 long 7 chars};
\node[iblock=1.2cm,below=2mm of info11] (info12) {Id2 long 7 chars};
\node[iblock=1.2cm] (info13) {Id3 long 7 chars};
\node[iblock=1.2cm,below=2mm of info13] (info14) {Id4 long 7 chars};
\node[iblock=1.2cm] (info15) {Id5 long 7 chars};
\node[iblock=1.2cm] (info16) {Id6 long 7 chars};
\node[iblock=1.2cm] (info17) {Id7 long 7 chars};
%2 chain
\node[iblock=34mm,right=of info11]
(info21) {Text1 long 34 chars};
\node[iblock=34mm,below=2mm of info21] (info22) {Text2 long 34 chars};
\node[iblock=34mm] (info23) {Text3 long 34 chars};
\node[iblock=34mm,below=2mm of info23] (info24) {Text4 long 34 chars};
\node[iblock=34mm] (info25) {Text5 long 34 chars};
\node[iblock=34mm] (info26) {Text6 long 34 chars};
\node[iblock=34mm] (info27) {Text7 long 34 chars};
%
\path[line,densely dotted,-](info12) edge (info13)
(info14) edge (info15)
(info15) edge (info16)
(info16) edge (info17);
%3 chain (lines with labels)
\path[line] (info11) edge node[oblock] {Label 1 long 20 chars} (info21)
(info12) edge node[oblock] {Label 2 long 20 chars} (info22)
(info13) edge node[oblock] {Label 3 long 20 chars} (info23)
(info14) edge node[oblock] {Label 4 long 20 chars} (info24)
(info15) edge node[oblock] {Label 5 long 20 chars} (info25)
(info16) edge node[oblock] {Label 6 long 20 chars} (info26)
(info17) edge node[oblock] {Label 7 long 20 chars} (info27);
% title and arrow
\node[oblock, text width=77mm, minimum height=9mm, align=center,
above right=7mm and -11mm of info11.north west]
(title) {Title};
\draw[line, line width=3mm,
-{Triangle[fill=bluei,length=3mm,width=6mm]}]
(title.south -| info11) -- (info11.north);
% comment 1
\node[draw,minimum width=77mm,above=2mm of title] {Comment 1};
% comment 2
\draw[decorate, decoration={brace,raise=1mm,amplitude=2mm},draw=bluei,thick]
(info21.north west) to node[above=5mm,
draw,black,thin,
minimum width=42mm,
align=left] {Comment 2\\ some more text} (info21.north east);
% comment 3
\draw[decorate, decoration={brace,raise=1mm,amplitude=2mm},draw=bluei,thick]
(info17.south west) to node[left=5mm,
draw,black,thin,
text width=19mm,
align=left] {Comment 3\\ some more text} (info11.north west);
% comment 4
\path let \p1 = (info17.west),
\p2 = (info27.east),
\n1 = {veclen(\x2-\x1,\y2-\y1)} in
node[draw,minimum width=\n1,align=left,
below right=5mm and 0mm of info17.south west]
{Comment 4\\ some more text};
\end{tikzpicture}
\end{document}
该 MWE 给出:
与您的代码相比我做了以下更改:
- 我将您的三张 tikz 图片合并为一张。
- 为了放置蓝色节点,我使用了
chain
TikZ 库。通过它,代码得到了显著简化。要使用它,我在图片选项中添加start chain=going below
,并在蓝色框的样式(我在中重命名iblock
)中添加选项on chain
。 - 对于花括号,我使用 TikZ 库
decorations.pathreplacing
。它们的使用是在MWE之后% comment 2
和上面的代码中% comment 3
- 对于箭头,我(重新)定义了样式
line
。如果您不喜欢缩短线条,只需擦除shorten >
即可shorten <
。 - 绿色框由连接蓝色框左列和右列的箭头放置。
- 标题和评论 1 的框相对于左上角的蓝色框(名为
info11
)放置 - 评论 2 和评论 3 的框的位置由花括号决定
如果您需要更多信息、代码/图片是如何组成的或者对它们有一些疑问,请告诉我。
编辑:
添加箭头很简单,所以,如果你从提供的代码中学到一些东西,你应该自己动手。无论如何,为了定位它,我通过中心 info11 节点的(不可见)垂直线与标题节点南侧的水平线的交点确定它的坐标:
(title.south -| info11)
。箭头基于line
样式,线宽和箭头长度和宽度局部改变。对于注释 4 的框,情况与箭头处相同...但是,我使用更复杂的路线来确定其大小。对于其宽度,我首先测量节点西边界
info17
与列东边界之间的距离。为此,使用了具有函数和的info12
tikz 库calc
veclen
let
垂直虚线我将链中的节点分组。首先,我增加它们之间的垂直距离,然后以节点之间的明确距离中断链,这些线不会出现。虚线基于将
line
实线局部更改为虚线的样式,并且可选择-
消除箭头。
就是这样。我希望给出的解释以及提供的代码将帮助您了解 TikZ。当然,您需要阅读 TikZ 手册(至少第 III 部分和有关使用的库的部分),参见此处的示例以及例如TeX示例ETC。