如何在范围内选定节点上方添加节点

如何在范围内选定节点上方添加节点

我想[X]在选定的节点处添加额外的节点(带箭头的块),[C]就像图中这样:

enter image description here

我有类似的东西,我该怎么办?

\begin{figure}[!h]
\centering
    \begin{tikzpicture}[node distance = 5mm and 7mm, start chain = going right, block/.style = {draw, align=center, font=\linespread{0.8}\small}]
        \begin{scope}[every node/.append style={on chain, join=by -Stealth}]
            \node (n0)  {A};
            \node (n1) [block]  {B};
            \node (n2) [block]  {C};
            \node (n3) [block]  {D};
            \node (n4)  {E};
        \end{scope}
    \end{tikzpicture}
\end{figure}

答案1

例如如下所示。

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,chains,arrows.meta}
\begin{document}
    \begin{tikzpicture}[node distance = 5mm and 7mm, start chain = going right, block/.style = {draw, align=center, font=\linespread{0.8}\small}]
        \begin{scope}[every node/.append style={on chain, join=by -Stealth}]
            \node (n0)  {A};
            \node (n1) [block]  {B};
            \node (n2) [block]  {C};
            \node (n3) [block]  {D};
            \node (n4)  {E};
        \end{scope}
        \node [block,above=of n2] (nx) {X};
        \draw [-Stealth] (nx) -- (n2);
    \end{tikzpicture}
\end{document}

branch或者在你的 上创建一个chain,输出如上:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,chains,arrows.meta,scopes}
\begin{document}
\begin{tikzpicture}[
   node distance = 5mm and 7mm,
   block/.style = {
       draw, align=center, font=\linespread{0.8}\small
       }
   ]

\begin{scope}[
   every node/.append style={
       on chain, join=by -Stealth
   },
   start chain = going right]

   \node (n0)  {A};
   \node (n1) [block]  {B};
   \node (n2) [block]  {C};
   { [start branch=x going above] } % scopes library is needed for this syntax
   \node (n3) [block]  {D};
   \node (n4)  {E};
\end{scope}

\begin{scope}[
   continue branch=x, % continue the branch we started above
   every node/.append style={on chain, join=by Stealth-} % note Stealth- instead of -Stealth
   ]
  \node [block] {X};
\end{scope}
\end{tikzpicture}
\end{document}

相关内容