从文本末尾引出

从文本末尾引出

我正在尝试在一行文本的末尾添加一个标注。下面是最小示例;完整示例有多行代码,这些代码显示在叠加层中,我想在每行代码的右侧添加一个标注,并添加一些注释。结果如下所示;正如您所看到的,标注不是位于文本的右侧,而是在文本的右侧。我做错了什么?

\documentclass{beamer} %
\usepackage{tikz}
\usepackage{verbatim}

\usetikzlibrary{arrows,shapes,backgrounds,positioning}

\begin{document}

\tikzstyle{every picture}+=[remember picture]
\tikzstyle{na} = [baseline=-.5ex]

\begin{frame}
\frametitle{Test}

\texttt{\footnotesize{
lines = spark.textFile(“hdfs://...”)} \tikz[na] \coordinate (anc1);
}

\begin{tikzpicture}{>=stealth,overlay,show background grid}

%\coordinate[right=2cm of anc1] (anc2);
%\draw[-] (anc1.north east) -- (anc2);
\node[rectangle callout,draw,inner sep=2pt,color=blue,fill=blue,text=white,align=left,
      callout absolute pointer=(anc1.north east),
      above right= 15pt and 0pt of anc1.north east]
      {\footnotesize CreateRDD};
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

更新:我按照建议使用了tikzmark。删除之前的行\begin{tikzpicture}肯定可以解决这个问题。但是,正如我之前提到的,我有多行此文本,当我使用\\\newline断行时,我遇到了同样的问题。我想我最初应该发布多行——我的 MWE 太小了。新代码和结果输出如下。任何帮助都将不胜感激...

\documentclass{beamer} %
\usepackage{tikz}
\usepackage{verbatim}

\usetikzlibrary{arrows,shapes,backgrounds,positioning,tikzmark}

\begin{document}

\tikzstyle{every picture}+=[remember picture]
\tikzstyle{na} = [baseline=-.5ex]

\begin{frame}
\frametitle{Test}

\texttt{\footnotesize{
lines = spark.textFile(“hdfs://...”)} \tikzmark{anc1} \\ %\tikz[na] \coordinate (anc1);
errors = lines.\textcolor{blue}{filter}(\alert{\_.startsWith(“ERROR”)})  tikzmark{anc2}
}
\begin{tikzpicture}{>=stealth,overlay,show background grid}

\node[rectangle callout,draw,inner sep=2pt,color=blue,fill=blue,text=white,align=left,
      callout absolute pointer=(pic cs:anc1.north east),
      above right= 15pt and 0pt of pic cs:anc1.north east]
      {\footnotesize CreateRDD};
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

答案1

您的代码的问题在于tikzpicture选项中使用了大括号而不是方括号,因此它们被忽略了:

\documentclass{beamer} %
\usepackage{tikz}
\usepackage{verbatim}

\usetikzlibrary{arrows,shapes,backgrounds,positioning}

\begin{document}

\tikzstyle{every picture}+=[remember picture]
\tikzstyle{na} = [baseline=-.5ex]

\begin{frame}
\frametitle{Test}

\texttt{\footnotesize{
lines = spark.textFile(“hdfs://...”)} \tikz[na] \coordinate (anc1);
}

\begin{tikzpicture}[>=stealth,overlay,show background grid]

%\coordinate[right=2cm of anc1] (anc2);
%\draw[-] (anc1.north east) -- (anc2);
\node[rectangle callout,draw,inner sep=2pt,color=blue,fill=blue,text=white,align=left,
      callout absolute pointer=(anc1.north east),
      above right= 15pt and 0pt of anc1.north east]
      {\footnotesize CreateRDD};
\end{tikzpicture}
\end{frame}
\end{document}

我建议你使用tikzmark库中放置一个标记,以便稍后用来放置标注:

在此处输入图片描述

代码:

\documentclass{beamer} %
\usepackage{tikz}
\usepackage{listings}
\usetikzlibrary{arrows,shapes,backgrounds,positioning,tikzmark}

\lstset{
  basicstyle=\footnotesize
  columns=fullflexible,
  breaklines=true
}

\tikzset{
  %every picture/.append style={remember picture},
 na/.style={baseline=-.5ex}
}

\begin{document}

\begin{frame}
\frametitle{Test}

{\ttfamily\footnotesize
lines = spark.textFile(“hdfs://...”)\tikzmark{anc1} \par
errors = lines.\textcolor{blue}{filter}(\alert{\_.startsWith(“ERROR”)})\tikzmark{anc2}
}

\begin{tikzpicture}[>=stealth,remember picture,overlay,show background grid]
\node[rectangle callout,draw,inner sep=2pt,color=red,fill=red!30,text=black,align=left,
      callout absolute pointer=({pic cs:anc1}),
      above right= 25pt and 0pt of {pic cs:anc1}]
      {\footnotesize CreateRDD};
\node[rectangle callout,draw,inner sep=2pt,color=blue,fill=blue,text=white,align=left,
      callout absolute pointer=({pic cs:anc2}),
      above right= 15pt and 40pt of {pic cs:anc2}]
      {\footnotesize CreateRDD};
\end{tikzpicture}
\end{frame}

\end{document}

请注意,最好使用\tikzset而不是\tikzstyle。另外, \footnotesize (和类似命令) 是开关,而不是带参数的命令,因此它们应在{\footnotesize text}{\footnotesize text\par}中用于长文本。

相关内容