答案1
一个例子:
\documentclass{article}
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{tikzmark, shapes.callouts}
\begin{document}
\begin{lstlisting}[mathescape]
this is the first$\tikzmark{aux}$ line
This is the second line
\end{lstlisting}
\begin{tikzpicture}[overlay, remember picture]
\node[rectangle callout, rounded corners,
callout absolute pointer={(pic cs:aux)},
draw] at ([yshift=1cm]pic cs:aux){Note};
\end{tikzpicture}
\end{document}
更新:beamer
我跳过了阅读这个问题。
\documentclass{beamer}
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{tikzmark, shapes.callouts}
\begin{document}
\begin{frame}[fragile]{First frame}
\begin{lstlisting}[mathescape]
this is the first$\tikzmark{aux}$ line
This is the second line
\end{lstlisting}
\begin{tikzpicture}[overlay, remember picture]
\node[rectangle callout, rounded corners, callout absolute pointer={(pic cs:aux)}, draw] at ([yshift=1cm]pic cs:aux){Note};
\end{tikzpicture}
\end{frame}
\end{document}