我正在尝试在 tikz 中绘制以下数据流图:
以下是我目前得到的信息:
\documentclass[10pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,positioning,petri}
\begin{document}
\begin{tikzpicture}[thick,
node distance=2cm,
on grid,
every transition/.style={fill=black,minimum width=.1cm, minimum height=0.9cm},
every label/.style={black!75}]
node distance=2cm,
on grid,
every transition/.style={fill=black,minimum width=.1cm, minimum height=0.9cm},
every label/.style={black!75}]
\node[place, label=above:$n_1$] (n1) {+};
\node[place, right=of n1, label=above:$n_2$] (n2) {$\times 2$};
\node[place, right=of n2, label=above:$n_3$] (n3) {+};
\node[place, below=of n2, label=above:$n_4$] (n4) {+1};
\node[place, right=of n3, label=above:$n_5$] (n5) {$\Delta(0)$};
\node[right of=n5] (x) {X};
\node[below of=n5] (y) {Y};
\node[left of=n1] (i) {Input};
\draw[->] (n1) edge (n2.west);
\draw[->] (n2) edge (n3.west);
\draw[->, to path={-| (\tikztotarget)}] (n4) edge (n3.south);
\draw[->] (n3) edge (n5.west);
\draw[->] (n5) edge (x);
\draw[->] (n4) edge (y);
\draw[->] (i) edge (n1.west);
\draw[->, to path={|- (\tikztotarget)}] (i) edge (n4.west);
\end{tikzpicture}
\end{document}
如您所见,绘制节点工作正常,但我无法正确绘制边缘。我希望边缘有角度,并且有圆点,这样可以清楚地看到流的分支。
我使用边缘绘制命令更新了我的代码。我仍然无法正确获得反馈边缘,也无法在边缘分支处获得点。
答案1
请尝试以下操作:
%\documentclass[10pt,a4paper]{article}
\documentclass[border=3.141592mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
decorations.markings,
positioning,
shadows, }
\begin{document}
\begin{tikzpicture}[
node distance = 7mm and 11mm,
start chain = A going right,
C/.style = {circle, minimum size=11mm, inner sep=1pt, outer sep=0pt,
draw, semithick, fill=gray!30},
dot/.style = {circle, fill, inner sep=2pt, outer sep = 0pt,
node contents={}},
every label/.style = {font=\small\sffamily},
every path/.style = {-Straight Barb}
]
\coordinate[label=above right:input] (in);
\node (d1) [dot, right=of in];
\begin{scope}[nodes = {C, on chain=A, join=by ->}]
\node (n1) [C, right=of d1] {+}; % A-1
\node (n2) [C] {$\times 2$};
\node (n3) [C] {+};
\node (n4) [C] {$\Delta(0)$}; % A-4
\end{scope}
\node (d2) [dot, right=of A-4];
\coordinate[right=of d2, label=above left:X] (x);
%
\node (A-5) [C, below=of A-2] {+1};
\node (d3) [dot, at={(A-5 -| A-3)}];
\coordinate[right=of d3, label=above left:Y] (y);
%
\draw (d2) |- ([yshift=7mm] A-1.north) edge (A-1)
(in) to (A-1) (d3) edge (A-3) (A-4) edge (x)
(A-5) edge (y);
\draw (d1) |- (A-5);
\end{tikzpicture}
\end{document}
编辑:
添加标签时,链的处理方式与上述不同:应将其添加到C
节点样式。这样做,不再需要宏join had to be interrupted because it should not connect last
C范围。node in code with others. In this case the
\documentclass[border=3.141592mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
backgrounds,
chains,
positioning}
\makeatletter
\tikzset{suspend join/.code={\def\tikz@after@path{}}}
\makeatother
\begin{document}
\begin{tikzpicture}[
node distance = 7mm and 11mm,
start chain = going right,
C/.style = {circle, minimum size=11mm, inner sep=1pt, outer sep=0pt,
draw, semithick, fill=gray!30, drop shadow,
on chain, join= by ->},
dot/.style = {circle, fill, inner sep=2pt, outer sep = 0pt,
node contents={}},
every label/.style = {label distance=5pt, inner sep=1pt,
font=\small\sffamily, fill=white},
every path/.style = {-Straight Barb}
]
\coordinate[label=above right:input] (in);
\node (d1) [dot, right=of in];
\node (n1) [C,label=$n_1$,
right=of d1] {+};
\node (n2) [C,label=$n_2$] {$\times 2$};
\node (n3) [C,label=$n_3$] {+};
\node (n4) [C,label=$n_4$] {$\Delta(0)$};
\node (d2) [dot, on chain];
\coordinate[on chain,
label=above left:X] (x);
\node (n5) [C, suspend join,
below=of n2,
label=$n_5$] {+1};
\node (d3) [dot, at={(n5 -| n3)}];
\coordinate[right=of d3, label=above left:Y] (y);
%
\scoped[on background layer]
\draw (d2) |- ([yshift=7mm] n1.north) edge (n1)
(in) to (n1) (d3) edge (n3) (n4) edge (x)
(n5) edge (y);
\draw (d1) |- (n5);
\end{tikzpicture}
\end{document}