连接路径到节点所包含的节点

连接路径到节点所包含的节点

我正在用 tikz 绘制一个框图,其中我有一个通过嵌套 tikzpictures 包含子节点的节点。

以下是 MWE:

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc} 

\begin{document}

\tikzstyle{virtual}=[coordinate]

\tikzstyle{block}=[draw, inner sep=3pt]

\begin{tikzpicture}[node distance=20pt]
    % nodes

    \node[virtual] (in) at (0mm,0mm) {};
    \node[block] (g) [right = of in] {G};

    \node[draw, anchor = east, inner xsep = 0, inner ysep = 5pt] (group) at ([xshift=100pt, yshift=50pt]g.west) {
    \begin{tikzpicture}
        \node[virtual] (in) at (0,0) {};
        \node[block] (a) [right =  of in] {$A$};
        \node[block] (b) [above =  of a] {$B$};
        \node[draw,
              circle,
              anchor = center,
              inner sep = 1pt,
              xshift = 20pt,
              minimum size=3pt,
             ] (sum) at ($(a.east)!0.5!(b.east)$) {};
        \draw [->] (in.east) -- (a.west);
        \draw [->] (in.east|-b) -- (b.west);
        \draw [->] (a.east) -| (sum.south);
        \draw [->] (b.east) -| (sum.north);
        \draw [-] (sum.east) -- ([shift={(10pt,0)}]sum.east);
        \end{tikzpicture}
    };


    %edges
    \draw[->] (g.east) -- ([shift={(100pt,0)}]g.east);
    \draw[->] ([shift={(10pt,0)}]g.east) |- (group.west); % <- I would like to connect to the in of block A

\end{tikzpicture}
\end{document}

其输出是

MWE 输出

正如我在图中用红色箭头画出的那样,我想将从节点输出上来的信号连接到与 children-node 对应位置的g节点。groupa

是否可以在不需要对 yshift 进行硬编码的情况下实现这一点?

答案1

这是为了礼貌地说服您永远不要嵌套tikzpictures。这不受支持,并且可能导致无法控制的错误。而且您不需要它。只需制作内部tikzpicturea的内容pic,并使用其坐标,如 pgfmanual(版本 3.1)第 261 页所述。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{calc} 

\begin{document}

\tikzset{virtual/.style={coordinate},
block/.style={draw, inner sep=3pt}}

\begin{tikzpicture}[node distance=20pt,
my subpicture/.pic={\begin{scope}[local bounding box=#1]
        \node[virtual] (in) at (0,0) {};
        \node[block] (a) [right =  of in] {$A$};
        \node[block] (b) [above =  of a] {$B$};
        \node[draw,
              circle,
              anchor = center,
              inner sep = 1pt,
              xshift = 20pt,
              minimum size=3pt,
             ] (sum) at ($(a.east)!0.5!(b.east)$) {};
        \draw [->] (in.east) -- (a.west);
        \draw [->] (in.east|-b) -- (b.west);
        \draw [->] (a.east) -| (sum.south);
        \draw [->] (b.east) -| (sum.north);
        \draw [-] (sum.east) -- ([shift={(10pt,0)}]sum.east);
    \end{scope}}]
    % nodes

    \node[virtual] (in) at (0mm,0mm) {};
    \node[block] (g) [right = of in] {G};

    \pic at ([xshift=33pt, yshift=50pt]g.west) (mypic) {my subpicture=group};
    \draw ([yshift=-5pt]group.south west) rectangle ([yshift=5pt]group.north east);


    %edges
    \draw[->] (g.east) -- ([shift={(100pt,0)}]g.east);
    \draw[->] ([shift={(10pt,0)}]g.east) |- (mypicin); % <- I would like to connect to the in of block A

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容