答案1
绘图本身可能很简单,但有些细节很棘手(例如连接mem_out
到的线val_in
)。我不会提供整个绘图,而是留下它的骨架,并说明如何完成这些棘手的细节。
由于需要连接大块的特定部分,因此应将它们绘制为节点。要使节点对齐,您可以使用\matrix
。 A\matrix
本身就是一个节点,因此像draw
和anchor
(或定位left=<dim> of <node>
)这样的节点选项有效。一旦您为矩阵指定<name>
,其中的节点就会自动命名为(<name>-<row num>-<col num>)
,这使得它们易于调用。
对于交叉线,我正在研究一个自动化解决方案,并提出了一个问题:使用 TikZ 精确装饰交叉点上的路径 - 避免交叉线,那里有一个可行的解决方案,但是非常有限,也有指向其他解决方案的链接。
数学家
\documentclass[tikz]{standalone}
\usetikzlibrary{matrix, positioning, intersections, decorations.pathreplacing, calc}
\tikzset{
over path/.style={
decoration={show path construction, lineto code={
\path[name path=this path] (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
\path[name intersections={of=this path and #1, total=\t}, /utils/exec={\global\let\t=\t}]%
let \n1={int(\t+1)} in%
(\tikzinputsegmentfirst) coordinate (int-0)%
foreach \i in {1,...,\n1}{%
\ifnum \i<\n1%
(intersection-\i) coordinate (int-\i)%
\else
(\tikzinputsegmentlast) coordinate (int-\n1)%
\fi};
\draw (\tikzinputsegmentfirst) foreach[remember=\i as \last (initially 0)] \i in {1,...,\t}{%
let \p1=($(int-\last)-(int-\i)$), \n1={veclen(\x1,\y1)}, \n2={abs(4pt)}, \n3={\i+1} in%
[rounded corners=\n2/4] -- ($(int-\last)!\n1-\n2!(int-\i)$) to[bend left=90, looseness=1.7] ($(int-\last)!\n1+\n2!(int-\n3)$)} -- (\tikzinputsegmentlast);
}
},
decorate
}
}
\begin{document}
\begin{tikzpicture}[>=latex]
\matrix (Memory) [matrix of nodes, draw, inner sep=0pt,
column 1/.style={anchor=west},
column 2/.style={anchor=east},
column sep=.5cm, row sep=.2cm,
nodes={font=\ttfamily, inner sep=4pt}]{%
rst & mem\_out \\
next\_val & \\};
\matrix (EES) [matrix of nodes, draw, inner sep=0pt,
below right=0cm and 2cm of Memory.north east,
column 1/.style={anchor=west},
column 2/.style={anchor=east},
column sep=1cm,
nodes={font=\ttfamily, inner sep=4pt}]{%
val\_in & data\_out \\
clk & \\
rst & req\_val \\};
\foreach \block in {Memory, EES} \node[font=\sffamily\Large, above=0cm of \block]{\block};
\draw[name path=line] ([shift={(1cm,0.4cm)}]Memory.north east) -- ++(0,-2cm);
\draw[over path=line, ->] (Memory-1-2) -- (EES-1-1);
\end{tikzpicture}
\end{document}