tikz 标注形状不适用于 alltt 环境

tikz 标注形状不适用于 alltt 环境

我想使用callout形状来tikz解释alltt环境中列出的程序的一些元素。但callout形状没有正确指向列表中所需的元素。

\documentclass{article}

\usepackage[papersize={7cm,2cm}]{geometry}
\usepackage{alltt}
\usepackage{tikz}
\usepgflibrary{shapes.callouts}
\usetikzlibrary{decorations.text}%workaround for undefined \pgf@test

\newcommand{\refnode}[2]{\tikz[remember picture,baseline=-.5ex]{\node[draw](#1){#2};}}

\begin{document}

\begin{alltt}
let \refnode{r}{greatest} a b =
  if a > b then a else b
\end{alltt}

\tikz[remember picture,overlay]{%
  \node[rectangle callout,fill=green!30,callout absolute pointer={(r)}]
     at (4,0) {function name};}

\end{document}

output

关于如何解决这个问题有什么线索吗?

答案1

您似乎在定义标注时缺少一个overlay参数。\node

\documentclass{article}

\usepackage[papersize={7cm,2cm}]{geometry}
\usepackage{alltt}
\usepackage{tikz}
\usetikzlibrary{shapes.callouts}
\usetikzlibrary{decorations.text}%workaround for undefined \pgf@test

\newcommand{\refnode}[2]{%
  \tikz[remember picture,baseline=-.5ex]{%
    \node[draw](#1){#2};
  }%
}

\begin{document}

\begin{alltt}
let \refnode{r}{greatest} a b =
  if a > b then a else b
\end{alltt}

\tikz[remember picture,overlay]{%
  \node[rectangle callout,fill=green!30,overlay,%
    callout absolute pointer={(r.east)}] at (4,0) {function name};
}

\end{document}

result

相关内容