以上就是我想要画的三张流程图,存在一些问题:
如何在第三张图片中添加
Dashed Box
和。Cross
Bond worth P
我不知道如何在第一张图片中添加矩形。
\documentclass[UTF8]{ctexart}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.geometric, arrows,calc,decorations.markings}
\tikzset{
process/.style={
text width=2.5cm, draw,
minimum height=1.6cm,
text centered,
},
process1/.style={
text width=2.5cm, draw,
minimum height=0.8cm,
text centered,
},
description/.style={
text centered,
text width=10cm,
},
myarrow/.style={
postaction={
decorate, decoration={
markings,mark=at position #1 with {\arrow{Stealth};
}
}
}
},
}
\usepackage{setspace}
\usepackage{etoolbox}
\AtBeginEnvironment{tikzpicture}{\singlespacing}
\begin{document}
\pagestyle{empty}
\begin{center}
\begin{tikzpicture}
\node[process] (p1) {Default\\ protection\\ buyer};
\node[process, right=10em of p1] (p2) {Default\\ protection\\ seller};
\draw[-Stealth, line width=1pt] ([yshift=-8ex, xshift=8ex]p2.west) -- node[description, above] {100} ([yshift=-8ex, xshift=-8ex]p1.east);
\draw [-Stealth, line width=1pt]([yshift= 8ex,xshift=0.5cm]$(p1)$) --node[midway] (Rect){}([yshift=8ex,xshift=-.5cm]$(p2)$);
\draw[fill=white] ($(Rect)+(-1.5,-0.7)$)rectangle($(Rect)+(1.5,0.7)$) node[midway] (Text){};
\node at (Text) {\begin{minipage}{3cm}\centering
Bond\\ worth P
\end{minipage}};
\end{tikzpicture}
\end{center}
\begin{center}
\begin{tikzpicture}
\node[process] (p1) {Asset Swap\\ Seller};
\node[process, right=8em of p1] (p2) {Asset Swap\\ Buyer};
\node[process1, right=4em of p2] (p3) {Bond};
\draw[-Stealth] ([yshift=2ex]p1.east) -- node[description, above] {C} ([yshift=2ex]p2.west);
\draw[-Stealth] ([yshift=-2ex]p2.west) -- node[description, below] {LIBOR + S} ([yshift=-2ex]p1.east);
\draw[-Stealth] (p3.west) -- node[description, below] {C} (p2.east);
\draw[dashed] ($(p1)+(-1.8,-1)$)rectangle($(p2)+(1.8,1)$);
\draw[ultra thick] ($(p3)+(-1.7,-0.8)$)--($(p3)+(1.7,0.8)$);
\draw[ultra thick] ($(p3)+(-1.7,0.8)$)--($(p3)+(1.7,-0.8)$);
\end{tikzpicture}
\end{center}
\end{document}
答案1
像这样:
编辑: 与您的代码相比,我做了以下更改,这使得代码更清晰、易于理解和简洁:
- 已
tikzlibrary
添加库fit
、、和已删除未在此图像中使用的positioning
库quotes
shapes.misc
tikz
使用的语法是正确的- 使用文档类
article
与包结合geometry
而不是ctexart
。这不会影响图像设计和可用性。 - 为流程图中所有框定义了新的通用样式,可以自动将文本分成更多行,节点周围有阴影,并具有确定节点宽度的选项(这样,所有使用的迷你页面都变得多余)
- 为了虚线框围绕“和”资产交换买方“我定义了新的节点样式
fbox
(作为框架框),它通过使用 tikz 库进行定位fit
- 为了划掉一个节点,使用库定义了新的框样式
shapes.misc
- 对于节点的定位使用库
positioning
,对于节点之间的线确定辅助坐标(c
,c1
和c2
),这简化了节点的绘制。 - 对于线上的标签使用库
quotes
- 我没有在你的文档中考虑行距。你的解决方案可以毫无问题地与此代码配合使用
\documentclass{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, fit, positioning, quotes,
shadows, shapes.geometric, shapes.misc}
\tikzset{FlowChart/.style =
{
box/.style = {rectangle, draw, fill=white,
text width=##1, minimum height=8mm, align=center,
inner sep=2mm, outer sep=0mm,
drop shadow={shadow xshift=2mm, shadow yshift=-2mm}
},
box/.default = 22mm,
cbox/.style = {cross out=1m, draw, very thick,
inner sep=3mm, node contents={}},
fbox/.style = {rectangle, draw, densely dashed, inner sep=4mm},
LA/.style = {semithick, -Triangle}
}
}
\begin{document}
\pagestyle{empty}
some text
\begin{center}
\begin{tikzpicture}[FlowChart,
node distance = 0mm and 8mm
]
\node (p1) [box] {Asset Swap Seller};
\node (p2) [box=32mm, above right=of p1] {Bond\\ worth P};
\node (p3) [box, below right=of p2] {Asset Swap Buyer};
%
\draw [LA] (p1 |- p2) -- (p2)
(p2) -- (p2 -| p3);
%
\coordinate[below=4mm of p1.south] (c);
\draw [LA] (p3.south |- c) to ["100"] (c);
% fake node,
\node[right=38mm of p3.east] {};
\end{tikzpicture}
\end{center}
some text
\begin{center}
\begin{tikzpicture}[FlowChart,
node distance = 0mm and 8mm
]
\node (p1) [box] {Asset Swap Seller};
\node (p2) [box, right=48mm of p1] {Asset Swap Buyer};
\node (p3) [box, right=16mm of p2] {Bond};
%
\node (p4) [fbox, fit=(p1) (p2)] {};
%
\coordinate[above=2mm of p1.east] (c1);
\coordinate[below=2mm of p1.east] (c2);
\draw [LA] (c1 -| p2.west) to ["C" '] (c1);
\draw [LA] (c2) to ["LIBOR + C" '] (c2 -| p2.west);
%
\draw [LA,very thick] (p3) to ["C" '] (p2);
\end{tikzpicture}
\end{center}
some text
\begin{center}
\begin{tikzpicture}[FlowChart,
node distance = 0mm and 8mm
]
\node (p1) [box] {Asset Swap Seller};
\node (p2) [box, right=48mm of p1] {Asset Swap Buyer};
\node (p3) [box, right=16mm of p2] {Bond};
%
\node (p4) [fbox, fit=(p1) (p2)] {};
\node [cbox, fit=(p3)];
%
\coordinate[above=2mm of p1.east] (c1);
\coordinate[below=2mm of p1.east] (c2);
\draw [LA] (c1 -| p2.west) to ["C" '] (c1);
\draw [LA] (c2) to ["LIBOR + C" '] (c2 -| p2.west);
%
\draw [LA,very thick] (p3) to ["C" '] (p2);
\end{tikzpicture}
\end{center}
some text
\end{document}
答案2
使用新样式进行编辑并添加阴影:
您需要的都在这里:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\usetikzlibrary{decorations.markings,calc}
\tikzset{
process/.style={
inner sep=0,
text width=2.5cm, draw,
minimum height=1.6cm,
text centered,
},
process1/.style={
text width=2.5cm, draw,
minimum height=0.8cm,
text centered,
},
description/.style={
text centered,
text width=10cm,
},
myarrow/.style={
postaction={
decorate, decoration={
markings,mark=at position #1 with {\arrow{Stealth};
}
}
}
},
}
\usepackage{setspace}
\usepackage{etoolbox}
\AtBeginEnvironment{tikzpicture}{\singlespacing}
\begin{document}
\pagestyle{empty}
\begin{center}
\begin{tikzpicture}
\fill[black!20!white] ($(-1.25,-0.8)+(0.25,-0.2)$)rectangle($(1.25,0.8)+(0.25,-0.2)$);
\node[process,fill=white](p1) at(0,0) {Default\\ protection\\ buyer};
\fill[black!20!white] ($(7.25,-0.8)+(0.25,-0.2)$)rectangle($(9.75,0.8)+(0.25,-0.2)$);
\node[process, right=6cm of p1,fill=white] (p2) {Default\\ protection\\ seller};
\fill[black!20!white] ($(2.95,0.4)+(0.25,-0.2)$)rectangle($(5.5,2.05)+(0.25,-0.2)$);
\draw[-Stealth] ([yshift=8ex, xshift=-7ex]p1.east) -- node[process,fill=white] {90 basis points per year} ([yshift=8ex, xshift=7ex]p2.west);
\draw[-Stealth, line width=1pt] ([yshift=-8ex, xshift=7ex]p2.west) -- node[description, above] {100} ([yshift=-8ex, xshift=-7ex]p1.east);
\end{tikzpicture}
\end{center}
\begin{center}
\begin{tikzpicture}
\fill[black!20!white] ($(-1.25,-0.8)+(0.25,-0.2)$)rectangle($(1.25,0.8)+(0.25,-0.2)$);
\node[process,fill=white] (p1) at (0,0) {Asset Swap\\ Seller};
\fill[black!20!white] ($(4,-0.8)+(0.25,-0.2)$)rectangle($(6.6,0.8)+(0.25,-0.2)$);
\node[process, right=8em of p1,fill=white] (p2) {Asset Swap\\ Buyer};
\fill[black!20!white] ($(8,-0.4)+(0.25,-0.2)$)rectangle($(10.7,0.4)+(0.25,-0.2)$);
\node[process1, right=4em of p2,fill=white] (p3) {Bond};
\draw[-Stealth] ([yshift=2ex]p1.east) -- node[description, above] {C} ([yshift=2ex]p2.west);
\draw[-Stealth] ([yshift=-2ex]p2.west) -- node[description, below] {LIBOR + S} ([yshift=-2ex]p1.east);
\draw[-Stealth] (p3.west) -- node[description, below] {C} (p2.east);
\draw[dashed] ($(p1.south west)-(1,0.5)$)rectangle($(p2.north east)+(1,0.5)$);
\draw[ultra thick] ($(p3)-(1.2,-0.7)$)--($(p3)+(1.2,-0.7)$);
\draw[ultra thick] ($(p3)-(1.2,0.7)$)--($(p3)+(1.2,0.7)$);
\end{tikzpicture}
\end{center}
\end{document}
与上一个相比,新内容是,对于矩形,我们给出两个对角,并在它们之间加上矩形一词。(我将其填充为白色,以删除箭头的先前部分)。此外,虚线选项适用于矩形,也适用于线条。最后,将坐标添加到点上,可以使用已知坐标绘制线条或形状。
对于阴影来说,没有带有起点的代码会更容易,而移位并没有真正的帮助(right=of 和 right of 并不真正适合这种情况)
输出: