编辑

编辑

我想在图形上标记不同位置。我想使用标注,因为标注很容易移动,但我更喜欢使用箭头而不是标准笔尖。有人见过这样的代码吗?或者有人想写一下吗?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.callouts}
\usetikzlibrary{decorations.text}
\usetikzlibrary{positioning}
\begin{document}
\tikzset{markplace/.style=
 {rectangle callout,
  fill=orange,
  callout absolute pointer={#1},
  at={#1},
  above=1cm  
  }}

\begin{tikzpicture}
\draw[fill,green] (1,1) circle (1pt);

\node[markplace={(1,1)}] {here};

\node[markplace={(1,1)},below left=2cm and 0.5cm] {and here};

\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑

我现在想出了这个代码(我自然会写一些包装器代码,但还没有决定语法):它找到标注的位置而不绘制它。然后从中心绘制箭头,然后在其上方绘制矩形。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.callouts}
\usetikzlibrary{decorations.text}
\usetikzlibrary{positioning}

\begin{document}
\tikzset{markplace/.style=
 {rectangle callout,
  fill=none,draw=none,
  callout absolute pointer={#1},  
  at={#1},
  above=1cm
  }}


\begin{tikzpicture}
\draw[fill,green] (1,1) circle (1pt);

\tikzset{shorten >=1pt}

\node[markplace={(1,1)}] (B) {here};
  \draw[-latex,thick,orange] (B.center)--(1,1);
\node[anchor=center,at=(B.center),fill=orange,rectangle]{here};


\node[markplace={(1,1)},below left=2cm and 0.5cm] (B) {and here};
  \draw[-latex,thick,orange] (B.center)--(1,1);
\node[anchor=center,at=(B.center),fill=orange,rectangle]{and here};


\node[markplace={(0,1)},above left=-1cm and 3cm] (B) {blub};
  \draw[-latex,thick, red] (B.center)--(1,1);
\node[anchor=center,at=(B.center),fill=orange,rectangle]{blub};


\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

这我思考可以。我“简单”破解了背景路径,rectangle callout shape并插入一些条件代码以允许tikz调出指针的路径。

请注意,路径是从形状的中心绘制的,因此如果没有填充,它看起来会很丑(如果是从形状的边框绘制的,则形状和线的起点之间可能会有间隙)。

\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.callouts}
\usetikzlibrary{positioning}

\newif\iftikzcalloutarrow

% Ooo this is naughty...
%
\def\hack#1\fi\fi#2\endhack{%
 \expandafter\def\csname pgf@sh@bg@rectangle callout\endcsname{%
    #1\fi\fi%
    \iftikzcalloutarrow
      % New pointer code
        \pgfscope\path[rectangle callout arrow options/.try] 
          \pgfextra{\pgfpathmoveto{\centerpoint}\pgfpathlineto{\calloutpointer}};
        \endpgfscope%
        \pgfpathmoveto{\beforecalloutpointer}%
        \pgfpathlineto{\aftercalloutpointer}%
        {%
            \pgftransformshift{\centerpoint}%
            \pgfpathlineto{\firstpoint}\pgfpathlineto{\secondpoint}%
            \pgfpathlineto{\thirdpoint}\pgfpathlineto{\fourthpoint}%
            \pgfpathclose%
        }%
    \else%
    #2
    \fi}%
}
\expandafter\expandafter\expandafter\hack\csname pgf@sh@bg@rectangle callout\endcsname\endhack

\tikzset{%
    markplace/.style={%
        rectangle callout,
    fill=orange,text=black,
    callout absolute pointer={#1},
    at={#1},
    above=1cm  
  }, 
  rectangle callout arrow/.code={%
    \tikzcalloutarrowtrue%
    \tikzset{rectangle callout arrow options/.style={#1}}%
  }
}


\begin{document}


\begin{tikzpicture}

\draw[fill,green] (1,1) circle [radius=1pt];
\node[markplace={(1,1)}] {here};
\node[markplace={(1,1)}, rectangle callout arrow={draw=orange, -stealth},
  below left=2cm and 0.5cm] {and here};

\node[markplace={(1,1)}, rectangle callout arrow={draw=black, -latex, dashed},
  below right=1cm and 0.5cm] {and also here};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容