有tikz
没有什么方法可以让callout
形状指向多个地方?
我想使用一个callout
形状来解释图表的某些部分。此callout
形状将指向图表中的不同元素,因为对于一组元素而言,解释是相同的。
这是一个最小的工作示例:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,shapes,arrows}
\begin{document}
\begin{tikzpicture}[node distance=2cm, auto]
\node[state,initial] (s0) {$s_0$};
\node[state] (s1) [right of=s0] {$s_1$};
\node[state,accepting] (s2) [right of=s1] {$s_2$};
\path[->]
(s0) edge node {a} (s1)
(s1) edge node {c} (s2)
edge [loop above] node {b} ();
\node[fill=green!20, rectangle callout, callout absolute pointer={(s0.south)}]
[below of=s0] {
\parbox{2cm}{Each circle is a \emph{state} of the automaton}};
\end{tikzpicture}
\end{document}
产生输出
我想要callout
指向自动机的所有三个节点。
答案1
这将更新(→ 第一次修订) 包括一个改进的multiple absolute pointers
密钥。
现在要使用的形状取自常用shape
键(默认值:矩形)。不要使用该选项rectangle callout
!它将自动使用。
无星号版本会绘制一个额外的节点(但没有指针)。多个指针列表现在可以理解仅影响该指针的标注形状的可选选项。
draw
显然,除了 之外,这与其他任何选项都不太兼容none
。不跨越任何指针的边框必须手动绘制(这对于形状来说已经够难了rectangle callout
)。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{automata,shapes,arrows}
\makeatletter
\tikzset{
expand me/.style={#1},
multiple absolute pointers/.style args={#1[#2]#3#4}{
insert path={
\foreach \qrr@tikz@calloutabsolutepointer in {#3} {
\pgfextra
\expandafter\pgfutil@ifnextchar\expandafter[%
\expandafter\qrr@tikz@parse@calloutabsolutepointer\expandafter{%
\expandafter\qrr@tikz@parse@calloutabsolutepointer\expandafter[\expandafter]\expandafter}\qrr@tikz@calloutabsolutepointer\@qrr@tikz@parse@calloutabsolutepointer
\endpgfextra
node[#2, shape/.expanded=\tikz@shape\space callout, expand me/.expanded=\qrr@tikz@calloutabsolutepointer@options, callout absolute pointer={(\qrr@tikz@calloutabsolutepointer@)}] {#4}
}
\pgfextra
\def\pgf@tempa{#1}
\pgfutil@in@*{#1}
\ifpgfutil@in@\else
\pgfkeysalso{insert path={node[#2] {#4}}}
\fi
\endpgfextra}}}
\def\qrr@tikz@parse@calloutabsolutepointer[#1]#2\@qrr@tikz@parse@calloutabsolutepointer{%
\gdef\qrr@tikz@calloutabsolutepointer@options{#1}%
\gdef\qrr@tikz@calloutabsolutepointer@{#2}%
}
\makeatother
\begin{document}
\begin{tikzpicture}[node distance=2cm, auto]
\node[state,initial] (s0) {$s_0$};
\node[state] (s1) [right of=s0] {$s_1$};
\node[state,accepting] (s2) [right of=s1] {$s_2$};
\path[->]
(s0) edge node {a} (s1)
(s1) edge node {c} (s2)
edge [loop above] node {b} ();
\path[multiple absolute pointers={
[fill=green!20, text width=2.1cm, below of=s0]
{[fill=blue!20]s1.south,[fill=red!20]s2.south,[fill=yellow!60]s0.south}
{Each circle is a \emph{state} of the automaton}
}];
\end{tikzpicture}
\end{document}