移动一条带有节点的线来连接节点,节点锚点在哪里?

移动一条带有节点的线来连接节点,节点锚点在哪里?

请考虑以下 mwe:

    \documentclass[tikz,border=5mm]{standalone}
    \usetikzlibrary{arrows,calc,chains,positioning,shapes.callouts}
\begin{document}
    \begin{tikzpicture}[
    every   pin/.style = {pin distance=9mm, pin edge={<-,solid,black,shorten <>=0mm}, 
                          text=blue},
     shorten <>/.style = {shorten >=#1, shorten <=#1},
           Line/.style = {line width=2.4mm, gray, -triangle 60, shorten <>=2mm},
    node distance=33mm,
    start chain = going below,    
                        ]
\node   (a) [draw,minimum width=44mm,on chain]    {node 1};
\node   (b) [draw,minimum width=44mm,on chain]    {node 2};
    \draw (a) -- (b);
    \draw[Line,transform canvas={xshift=7mm}] 
          (a) to node (c) [inner sep=0pt,text=white,pin=below  left:line 1] {1}   (b);
    \draw[Line,transform canvas={xshift=19mm}]
          (b) to node (d) [inner sep=0pt,text=white,pin=below right:line 2] {2}   (a);
\node[rectangle callout,draw,callout absolute pointer=(c.west),
      align=center, above left=3mm of c.west]  {note about\\   line num. 1};
\node[rectangle callout,draw,callout absolute pointer=(d.east),
      align=center, above right=3mm of d.east]  {note about\\   line num. 2};
      \end{tikzpicture}
\end{document}

mwe 中线移位的解决方案取自在 TikZ 中移动连接节点的线。我喜欢它,因为它使我能够在范围内移动行数。

我想知道,为什么线上的节点在正确的位置,但使用它们的名称作为另一个节点的锚点却会产生(对我来说)意想不到的结果:就像移位线上的节点实际上在非移位线上?

在此处输入图片描述

答案1

使用scopes 以便transform canvas正确地应用于所有必要的元素(行在本例中为标注),而不仅仅是特定的\draw

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,chains,positioning,shapes.callouts}

\begin{document}

\begin{tikzpicture}[
every   pin/.style = {
  pin distance=9mm,
  pin edge={<-,
    solid,black,
    shorten <>=0mm
    }, 
  text=blue
},
shorten <>/.style = {
  shorten >=#1,
  shorten <=#1
},
Line/.style = {
  line width=2.4mm, 
  gray,
  -triangle 60,
  shorten <>=2mm
},
node distance=33mm,
start chain = going below,    
]
\node (a) [draw,minimum width=44mm,on chain] {node 1};
\node (b) [draw,minimum width=44mm,on chain] {node 2};
\draw (a) -- (b);
\begin{scope}[transform canvas={xshift=7mm}]
  \draw[Line] 
    (a) to node (c) [inner sep=0pt,text=white,pin=below  left:line 1] {1}   (b);
  \node[rectangle callout,draw,callout absolute pointer=(c.west),
    align=center, above left=3mm of c.west]  {note about\\   line num. 1};
\end{scope}
\begin{scope}[transform canvas={xshift=19mm}]
  \draw[Line]
    (b) to node (d) [inner sep=0pt,text=white,pin=below right:line 2] {2}   (a);
  \node[rectangle callout,draw,callout absolute pointer=(d.east),
    align=center, above right=3mm of d.east]  {note about\\   line num. 2};
\end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容