我必须在 TikZ 中制作以下框图。由于我是新手,我可以制作一个简单的水平框图,但是,我无法像下图所示那样连接块。请有人提供 TikZ 代码。我有一个复杂的框图,我刚刚添加了其中的一部分。一旦我理解了这一点,我就可以绘制完整的图表。
这就是我目前拥有的代码:
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,positioning,shadows,shapes}
\begin{document}
\pagestyle{empty}
\tikzstyle{line} = [draw, -latex']
\tikzset{label/.style={draw=gray, ultra thin, rounded corners=.25ex, fill=gray!20,text width=4cm, text badly centered, inner sep=2ex, anchor=east, minimum height=4em}}
\begin{figure}[!htb]
\centering
\resizebox{\textwidth}{!}{%
\begin{tikzpicture}[node distance=5cm,auto,>=latex']
% Place nodes
\node [label] (init) {One};
\node [label, right of=init] (node) {One A1};
\node [label, right of=node] (node1) {One A2};
\node [label, right of=node1] (node2) {One B1};
\node [label, right of=node2] (node3) {One B2};
\node [label, right of=node3] (node4) {Two};
% Draw edges
\path [line] (init) -- (node);
\path [line] (node) -- (node1);
\path [line] (node1) -- (node2);
\path [line] (node2) -- (node3);
\path [line] (node3) -- (node4);
\end{tikzpicture}
}
\caption{Figure caption}
\label{fig:dummy}
\end {figure}
\end{document}
代码的输出是
答案1
我对乳胶了解不多,这是我第一次画这样的图,但这些功能似乎很容易理解。我搜索并阅读这个答案。我使用它的代码作为我的答案的模板。
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,shapes.geometric}
\begin{document}
\begin{tikzpicture}[>=latex']
\tikzset{block/.style= {draw, rectangle, align=center,minimum width=2cm,minimum height=1cm},
}
\node [block] (start) {One};
\node [coordinate, right = 0.5cm of start] (ADL){};
\node [coordinate, above = 1cm of ADL] (AUL){};
\node [coordinate, right = 0.5cm of start] (BUL){};
\node [coordinate, below = 1cm of BUL] (BDL){};
\node [block, right = 0.5cm of AUL] (A1){One A1};
\node [block, right = 0.5cm of BDL] (B1){One B1};
\node [block, right = 1cm of A1] (A2){One A2};
\node [block, right = 1cm of B1] (B2){One B2};
\node [coordinate, right = 0.5cm of A2] (AUR){};
\node [coordinate, below = 0.75cm of AUR] (ADR){};
\node [coordinate, right = 0.5cm of B2] (BDR){};
\node [coordinate, above = 0.75cm of BDR] (BUR){};
\node [coordinate, right = 0.5cm of BUR] (BEnd){};
\node [coordinate, right = 0.5cm of ADR] (AEnd){};
\node [block, above right = 0cm and 1cm of B2] (end){Two};
\path[draw, ->]
(start) -- (ADL)
(ADL) -- (AUL)
(AUL) edge (A1)
(A1) edge (A2)
(A2) -- (AUR)
(AUR) -- (ADR)
(ADR) edge (AEnd)
(start) -- (BUL)
(BUL) -- (BDL)
(BDL) edge (B1)
(B1) edge (B2)
(B2) -- (BDR)
(BDR) -- (BUR)
(BUR) -- (BEnd)
;
\end{tikzpicture}
\end{document}
答案2
好的,已经宣布了一个使用 tikz 的解决方案......但无论如何:
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows,calc,positioning,shadows,shapes}
\begin{document}
\begin{tikzpicture}[
> = latex',
node distance = 0mm and 3mm,
mynode/.style = {name=n#1,
draw, minimum height=7mm, minimum width=22mm,
inner sep=1mm, outer sep = 0mm}
]
%---
\node[mynode=1] {One};
\node[mynode=2,above right=0mm and 6mm of n1] {one A1};
\node[mynode=3,right= of n2] {one A2};
\node[mynode=4,below right=0mm and 6mm of n3] {Two};
\node[mynode=5,below right=0mm and 6mm of n1] {one B1};
\node[mynode=6,right= of n5] {one B2};
\coordinate[right=3mm of n1] (a);
\coordinate[above left=2mm and 3mm of n4.west] (b1);
\coordinate[below left=2mm and 3mm of n4.west] (b2);
\draw (n1) -- (a);
\draw[->] (a) |- (n2);
\draw[->] (a) |- (n5);
\draw[->] (n2) -- (n3);
\draw[->] (n3) -| (b1) -- (b1 -| n4.west);
\draw[->] (n5) -- (n6);
\draw[->] (n6) -| (b2) -- (b2 -| n4.west);
%-------
\end{tikzpicture}
\end{document}
在上面的代码中,我省略了所有不必要的包。结果和您在问题中所展示的是一样的。
答案3
借助强大的 PSTricks 解决方案xfp
包裹:
\documentclass{article}
\usepackage[margin = 4cm]{geometry} % avoids `overfull \hbox' (adjust the margins according to the values of `\sizeW` and `\spreadW`)
\usepackage{pstricks}
\usepackage{xfp}
\newcommand*\adjustW[2]{\fpeval{#1*\sizeW+#2*\spreadW}}
\newcommand*\adjustH[2]{\fpeval{#1*\sizeH+#2*\spreadH}}
\begin{document}
\begin{center}
% horizontal adjustment
\def\sizeW{2.3}
\def\spreadW{0.5}
% vertical adjustment
\def\sizeH{1.2}
\def\spreadH{2.4}
% drawing
\begin{pspicture}(\adjustW{4}{5},\adjustH{1}{1})
\psset{dimen = m, arrows = ->}
\psframe(0,\adjustH{0}{0.5})(\sizeW,\adjustH{1}{0.5})
\rput(\adjustW{0.5}{0},\adjustH{0.5}{0.5}){One}
\psline(\sizeW,\adjustH{0.5}{0.5})(\adjustW{1}{1},\adjustH{0.5}{0.5})
\psline{<->}(\adjustW{1}{2},\adjustH{0.5}{1})(\adjustW{1}{1},\adjustH{0.5}{1})%
(\adjustW{1}{1},\adjustH{0.5}{0})(\adjustW{1}{2},\adjustH{0.5}{0})
\psframe(\adjustW{1}{2},\spreadH)(\adjustW{2}{2},\adjustH{1}{1})
\rput(\adjustW{1.5}{2},\adjustH{0.5}{1}){One A$1$}
\psframe(\adjustW{1}{2},0)(\adjustW{2}{2},\sizeH)
\rput(\adjustW{1.5}{2},\adjustH{0.5}{0}){One B$1$}
\psline(\adjustW{2}{2},\adjustH{0.5}{1})(\adjustW{2}{3},\adjustH{0.5}{1})
\psline(\adjustW{2}{2},\adjustH{0.5}{0})(\adjustW{2}{3},\adjustH{0.5}{0})
\psframe(\adjustW{2}{3},\spreadH)(\adjustW{3}{3},\adjustH{1}{1})
\rput(\adjustW{2.5}{3},\adjustH{0.5}{1}){One A$2$}
\psframe(\adjustW{2}{3},0)(\adjustW{3}{3},\sizeH)
\rput(\adjustW{2.5}{3},\adjustH{0.5}{0}){One B$2$}
\psline(\adjustW{3}{3},\adjustH{0.5}{1})(\adjustW{3}{4},\adjustH{0.5}{1})%
(\adjustW{3}{4},\adjustH{0.75}{0.5})(\adjustW{3}{5},\adjustH{0.75}{0.5})
\psline(\adjustW{3}{3},\adjustH{0.5}{0})(\adjustW{3}{4},\adjustH{0.5}{0})%
(\adjustW{3}{4},\adjustH{0.25}{0.5})(\adjustW{3}{5},\adjustH{0.25}{0.5})
\psframe(\adjustW{3}{5},\adjustH{0}{0.5})(\adjustW{4}{5},\adjustH{1}{0.5})
\rput(\adjustW{3.5}{5},\adjustH{0.5}{0.5}){Two}
\end{pspicture}
\end{center}
\end{document}
您所要做的就是选择水平和垂直距离,绘图就会进行相应的调整。
答案4
这是另一张照片。使用positioning
库设置节点,\foreach
使用循环创建连接。箭头的位置可以通过angle
节点的连接来设置。
\documentclass[tikz, border=5mm]{standalone}
\usetikzlibrary{calc, positioning}
\tikzset{
every node/.style={
rectangle,
draw,
minimum width=2cm,
minimum height=1cm
},
>=latex,
}
\begin{document}
\begin{tikzpicture}[node distance=.25cm and 1cm]
% Nodes
\node (one) {One};
\node (a1) [above right=of one] {One A1};
\node (a2) [right=of a1] {One A2};
\node (b1) [below right=of one] {One B1};
\node (b2) [right=of b1] {One B2};
\node (two) [below right=of a2] {Two};
% Connectors
\begin{scope}[->]
\foreach \x\r in {a/165,b/195} {
\draw (one) -| ($(one)!.5!(\x1)$) |- (\x1);
\draw (\x1) -- (\x2);
\draw (\x2) -| ($(\x2)!.5!(two)$) |- (two.\r);
}
\end{scope}
\end{tikzpicture}
\end{document}