标记绘制节点

标记绘制节点

抱歉,这必须极其简单,但我找不到...我想标记图像(使用效果很好\node[circle],但现在我需要指向彼此靠近的位置,我想通过像在 mwe 中那样有尖锐的东西来实现,但(与 mwe 不同)我想把它们放在一个位置,相对位置,标记它们,...就像我对所做的那样\node,就像我在评论中指出的那样。标签不应随绘制的形状旋转(但我可以使用易于放置、缩放和旋转的形状,为每个形状添加第二个标记节点)。我根本看不到如何使用\node预定义形状以外的任何东西来创建(或者我可以定义自己的非元素形状并在那里使用吗?如果是这样,就找不到它)

    \documentclass[border=1mm]{standalone}
    \usepackage{amsmath}
    \usepackage{tikz}
    
    
    \begin{document}
    
        \begin{tikzpicture}
    
            %pointing circle
            \draw [fill=gray] (1,1) arc [start angle=0, end angle=270, radius=1cm] -- (1,0) -- (1,1);
            \node (n) at (0,1) {1};
            
            
            %\node[pointingcircle, rotate=-90, scale=0.5] (n) at (0,1) {1};
    
        \end{tikzpicture}
    \end{document}

答案1

基于预定义的节点形状circlerectanglethree forth circle,下面提供了自定义节点形状。

\documentclass[border=1mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz}

\makeatletter
\pgfdeclareshape{three forth circle}
{%
  \inheritsavedanchors[from=circle]%
  \pgfutil@for\@anchor:=center,%
      north,south,west,east,%
      mid,mid west,mid east,base,base west,base east,%
      north west,north east,south west,%
      % south east%
  \do{%
    \inheritanchor[from=circle]{\@anchor}%
  }%
  \anchor{south east}{%
    \centerpoint
    \pgf@xa=\radius
    \advance\pgf@x by\pgf@xa
    \advance\pgf@y by-\pgf@xa
  }%
  \backgroundpath{%
    \pgfutil@tempdima=\radius%
    \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
    \ifdim\pgf@xb<\pgf@yb%
      \advance\pgfutil@tempdima by-\pgf@yb%
    \else%
      \advance\pgfutil@tempdima by-\pgf@xb%
    \fi%
    %% draw border
    % move to south east
    \pgfpathmoveto{\pgfpointadd{\centerpoint}{\pgfqpoint{\pgfutil@tempdima}{-\pgfutil@tempdima}}}%
    % line to east
    \pgfpathlineto{\pgfpointadd{\centerpoint}{\pgfqpoint{\pgfutil@tempdima}{0pt}}}%
    % arc to south
    \pgfpatharc{0}{270}{\pgfutil@tempdima}%
    % close (line to south east)
    \pgfpathclose
  }%
  \anchorborder{%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \edef\pgf@marshal{%
      \noexpand\pgfpointborderellipse
      {\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}
      {\noexpand\pgfqpoint{\radius}{\radius}}%
    }%
    \ifdim\pgf@xa>0pt
      \ifdim\pgf@ya<0pt
        \edef\pgf@marshal{%
          \noexpand\pgfpointborderrectangle
          {\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}
          {\noexpand\pgfqpoint{\radius}{\radius}}%
        }%
      \fi
    \fi
    \pgf@marshal%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \centerpoint%
    \advance\pgf@x by\pgf@xa%
    \advance\pgf@y by\pgf@ya%
  }%
}
\makeatother


\begin{document}
  \begin{tikzpicture}
    \node[draw, fill=gray, three forth circle] (x) {x};
    
    % test anchor "south east"
    \draw[blue, ->] (1,0) -- (x.south east);
    % test \anchorborder
    \draw[help lines] foreach \i in {10,20,...,360} {(\i:1cm) -- (x)};
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容