我想使用具有一个输入和两个输出的块绘制一个框图。为了正确定位它们,我想为这些输出定义锚点。
我该如何定义这样的事情?
我像这样定义块
\tikzstyle{block} = [draw, rectangle,
minimum height=4em, minimum width=5em, align=center]
然后我想放置两个块并将第一个块的第一个输出与第二个块的输入连接起来,使得该线完全笔直,如下所示:
\draw
node at (0,0) [block] (A) {}
node at (6,1) [block] (B) {};
\draw [->] (A.output1) -- node {} (B.input);
我可以以某种方式定义点 A.output1、A.output2 和 B.input 吗?
谢谢!
答案1
锚input
仅仅是锚的别名,west
而output 1/2
锚output 2/2
的测量范围是东北锚和西北锚之间的三分之一和三分之二。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\makeatletter
\pgfset{
alias anchor/.code 2 args=\pgfdeclaregenericanchor{#1}{\pgf@sh@reanchor{##1}{#2}},
generate anchors'/.code n args={4}{%
\pgfmathloop\pgfmathparse{\pgfmathcounter/(#2+1)}%
\pgfset{generate anchor/.expanded={#1 \pgfmathcounter/#2}:{\pgfmathresult}:{#3}:{#4}}%
\ifnum\pgfmathcounter<#2\relax\repeatpgfmathloop},
generate anchor/.code args={#1:#2:#3:#4}{%
\pgfdeclaregenericanchor{#1}{%
\pgfpointlineattime{#2}{\pgf@sh@reanchor{##1}{#3}}{\pgf@sh@reanchor{##1}{#4}}}},
generate anchors/.style n args={3}{
/utils/tempa/.style={/pgf/generate anchor={##1:#2:#3}}, /utils/tempa/.list={#1}}}
\makeatother
\pgfset{
alias anchor={input}{west},
generate anchors'={output}{2}{north east}{south east}}
\begin{document}
\begin{tikzpicture}[
block/.style={
draw, rectangle, minimum height=4em, minimum width=5em, align=center},
]
\node[block] (A) {}
node[block, right=of A.output 2/2, anchor=input] (B) {};
\draw[->] (A.output 2/2) -- (B.input);
\draw[->] (A.output 1/2) -- +(right:.5);
\draw[<-] (A.input) -- +(left:.5);
\end{tikzpicture}
\end{document}