我想绘制如下图所示:
但是我在画图时遇到困难,特别是块 D、E 和 F。有人能帮帮我吗?
这是我编写的代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}
\usetikzlibrary{arrows.meta, chains, shapes}
\makeatletter
\tikzset{
suppress join/.code={\def\tikz@after@path{}},
}
\makeatother
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amsfonts}
\begin{document}
\begin{tikzpicture}[%
node distance = 2mm and -2mm, % Global setup of box spacing
start chain = going above, % General flow is top-to-bottom
%
LA/.style = {Stealth-},
base1/.style = {draw,
minimum size=6ex, inner sep=2mm, align=center,
on chain, join=by LA},
base2/.style = {draw,
minimum size=8ex, inner sep=2mm, align=center,
on chain, join=by LA},
sbox/.style = {base1, rectangle, text width=11em},
sbox2/.style = {base2, rectangle, text width=8em},
sbox3/.style = {base2, rectangle, text width=8em},
wbox/.style = {base1, rectangle, text width=25em},
term/.style = {sbox, rectangle, rounded corners},
test/.style = {base1, diamond, aspect=1.5,
inner xsep=0mm, text width=8em},
]
% from bottom to top
\node (n1) [term] {END};
\node (n2) [wbox] {I};
\node (n4) [sbox3] {DDDDDDDD};
% left column
\node (n5a) [sbox, suppress join, above left=of n4] {TTTTTT};
\node (n7a) [sbox] {BBBBBBBB};
% right column
\node (n5b) [sbox, suppress join, above right=of n4] {TTTTT};
\node (n7b) [sbox] {CCCCCCCC};
% top column2
\node (n8) [wbox, suppress join, above=of n7a.north -| n4] {AAAAAAAA};
\node (n11) [term] {\large START};
%
%\draw[LA] (n4) edge (n3)
%(n8) edge (n4);
%\draw[LA] (n7a) edge (n7a |- n8.south) (n3) -| (n5a);
%\draw[LA] (n7b) edge (n7b |- n8.south) (n3) -| (n5b);
\end{tikzpicture}
\end{document}
答案1
对于某些事情,我不明白其目的。无论如何,我保留了你的样式,并创建了一些看起来像你从中截取的屏幕截图的东西。(但实际上,chains
无论如何都不应该总是尝试使用。)
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{positioning,calc,arrows.meta, chains}
\makeatletter
\tikzset{
suppress join/.code={\def\tikz@after@path{}},
}
\makeatother
\begin{document}
\begin{tikzpicture}[%
node distance = 1.5em and 2em, % Global setup of box spacing
start chain = going above, % General flow is top-to-bottom
%
LA/.style = {Stealth-},
base1/.style = {draw,
minimum size=6ex, inner sep=2mm, align=center,
join=by LA},
base2/.style = {draw,
minimum size=8ex, inner sep=2mm, align=center,
join=by LA},
sbox/.style = {base1, rectangle, text width=11em},
sbox2/.style = {base2, rectangle, text width=8em},
sbox3/.style = {base2, rectangle, text width=8em},
wbox/.style = {base1, rectangle, text width=25em},
term/.style = {sbox, rectangle, rounded corners},
test/.style = {base1, diamond, aspect=1.5,
inner xsep=0mm, text width=8em},
font=\sffamily
]
% from bottom to top
\node (n1) [on chain,term] {END};
\node (n2) [on chain,sbox3] {I};
\node (n3) [on chain,sbox3] {H};
\node (n4) [on chain,sbox3] {G};
\node[above=of n4,anchor=south east,xshift=-0.75em] (n5a) [sbox3] {B};
\node[above=of n4,anchor=south west,xshift=0.75em] (n5b) [sbox3] {C};
\node[left=of n5a,sbox3] (n6b) {E};
\node[above=of n6b,sbox3] (n6a) {D};
\node[below=of n6b,sbox3] (n6c) {F};
\node[right=of n5b,sbox3] (n7b) {E};
\node[above=of n7b,sbox3] (n7a) {D};
\node[below=of n7b,sbox3] (n7c) {F};
\path (n5a.north) -- (n5b.north) node[midway,above=1.5em,sbox3] (n8) {A};
\node[above=of n8,term] (n9) {START};
\foreach \Z in {a,b,c}
{\draw[LA] (n6\Z.east) -- ++ (1em,0) |- (n5a);
\draw[LA] (n7\Z.west) -- ++ (-1em,0) |- (n5b);}
\draw[LA] (n4.150) -- (n4.150|-n5a.south);
\draw[LA] (n4.30) -- (n4.30|-n5b.south);
\draw[-Stealth] (n8.-150) -- (n8.-150|-n5a.north);
\draw[-Stealth] (n8.-30) -- (n8.-30|-n5b.north);
\draw[LA] (n8) -- (n9);
\end{tikzpicture}
\end{document}
答案2
你的 MWE 对我来说有点熟悉 ;-)
我将把它重写如下:
\documentclass{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
positioning,
shapes}
\makeatletter
\tikzset{suppress join/.code={\def\tikz@after@path{}},}
\makeatother
\usepackage{amsmath, amssymb, amsthm}
\begin{document}
\begin{tikzpicture}[%
node distance = 6mm and 5mm, % Global setup of box spacing
start chain = going above, % General flow is bottom-to-top
%
LA/.style = {Stealth-},
LAA/.style = {Stealth-Stealth},
base/.style = {draw, inner sep=3mm, align=center,
on chain},
box/.style = {base, text width=#1,
join=by LA},
box/.default = 11em,
sbox/.style = {base, text width=7em},
term/.style = {box=5em, rounded corners, font=\large,
on chain, join=by LA},
test/.style = {base, diamond, aspect=1.5,
inner xsep=0mm, text width=8em,
on chain, join=by LA},
]
% from bottom to top
\node (n1) [box=5em] {END};
\node (n2) [box] {I};
\node (n3) [box] {G};
\node (n4) [box] {H};
% left sub column
\node (n5a) [sbox,
above left=of n4.north] {B};
% right sub column
\node (n5b) [sbox,
above right=of n4.north] {C};
% top column
\node (n6) [box, suppress join,
above=of n5a.north -| n4] {A};
\node (n11) [term] {START};
% left column
\node (nL1) [sbox,
left=of n5a.west |- n4] {F};
\node (nL2) [sbox] {E};
\node (nL3) [sbox] {D};
% right column
\node (nR1) [sbox,
right=of n5b.east |- n4] {F};
\node (nR2) [sbox] {E};
\node (nR3) [sbox] {D};
% connection notincluded in join macro
\draw[LA] (n4.north -| n5a) edge (n5a)
(n4.north -| n5b) edge (n5b)
(n5a) edge (n5a |- n6.south)
(n5b) edge (n5b |- n6.south)
% left column
(nL2) edge (n5a)
(nR2) -- (n5b)
;
\coordinate[left =2mm of n5a.west] (L);
\coordinate[right=2mm of n5b.east] (R);
\draw[LAA] (nL1)-| (L) |- (nL3);
\draw[LAA] (nR1)-| (R) |- (nR3);
\end{tikzpicture}
\end{document}