tikz 装饰创建箭头(定位问题)

tikz 装饰创建箭头(定位问题)

我想创建自己的箭头(一个十字形圆圈)。我尝试了,decorations.markings它成功了。但是,装饰进入了尖角节点。我希望装饰只接触该节点。你能帮助我吗?

这是我得到的:

我得到了什么

这就是我要的 :

我想要的是

我的代码:

\documentclass[a4paper,11pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows,decorations.markings}

\tikzset{
    entity/.style = {
        draw,rectangle,minimum height=1cm,minimum width=2cm
    },
    -contains/.style = {
        decoration={markings,
                mark=at position 1 with {
                    %\node[draw,circle,fill=white,anchor=south east] (circle) {};
                    \node[draw,circle,fill=white] (circle) {};
                    \draw[-] (circle.north west) -- (circle.south east);
                    \draw[-] (circle.north east) -- (circle.south west);
            }
        },
            postaction={decorate}
    }
}

\begin{document}
\begin{tikzpicture}
    \node[entity] (A) {\textbf{A}};
    \node[entity,below right=1 and 0.5 of A] (B){\textbf{B}};
    \draw[-contains] (A) -- (B);
\end{tikzpicture}
\end{document}

答案1

如果可以的话,您可以先制作一个带有十字的圆形节点,然后再画线。

下面我还展示了创建实际箭头的示例,但这也存在定位问题,除非线以 90 度角与节点相交。

代码输出

\documentclass[a4paper,11pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}
\pgfdeclarearrow{
  name=Contains,
  parameters= {\the\pgfarrowlength},  
  setup code={
   \pgfarrowssettipend{0pt}
   \pgfarrowssetlineend{-\pgfarrowlength}
   \pgfarrowlinewidth=\pgflinewidth
   \pgfarrowssavethe\pgfarrowlength
  },
  drawing code={
   \pgfpathcircle{\pgfpoint{-0.5\pgfarrowlength}{0pt}}{0.5\pgfarrowlength}
   \pgfpathmoveto{\pgfpoint{-0.85355\pgfarrowlength}{0.35355\pgfarrowlength}}
   \pgfpathlineto{\pgfpoint{-0.14644\pgfarrowlength}{-0.35355\pgfarrowlength}}
   \pgfpathmoveto{\pgfpoint{-0.14644\pgfarrowlength}{0.35355\pgfarrowlength}}
   \pgfpathlineto{\pgfpoint{-0.85355\pgfarrowlength}{-0.35355\pgfarrowlength}}
   \pgfusepathqstroke
  },
  defaults = { length = 7pt }
}
\tikzset{
    entity/.style = {
        draw,rectangle,minimum height=1cm,minimum width=2cm
    },
    contains/.style={
      draw,circle,fill=white,inner sep=0pt,minimum size=7pt,outer sep=0pt,
      path picture={
         \draw (path picture bounding box.north west) -- (path picture bounding box.south east);
         \draw (path picture bounding box.north east) -- (path picture bounding box.south west);
            }
        },
}

\begin{document}
\begin{tikzpicture}
    \node[entity] (A) {\textbf{A}};
    \node[entity,right=3cm of A] (A2) {\textbf{A}};
    \node[entity,below right=1 and 0.5 of A] (B){\textbf{B}};
    \node [contains,anchor=south] (c) at (B.145) {};
    \draw (A) -- (c);
    \draw [->,>=Contains] (A2) -- (B);
    \draw [->,>=Contains,blue] (A2) to[out=180,in=90] (B);
\end{tikzpicture}
\end{document}

相关内容