连接带有 tikzmark 标记的文本的节点

连接带有 tikzmark 标记的文本的节点

我正在编辑一段文本,需要用方框圈出单词(或短句,即非多行文本)来标记它们,并将这些方框与稍后要添加的文本连接起来。tikzmark似乎是标记单词的最佳选择,因为我将在给定的页面中标记任意数量的单词。tikznode似乎最适合添加和连接文本到这些tikzmark编辑文本,因为我想在页面中任何我认为合适的位置添加自己的文本。

我发现很难连接节点并将它们相对于标记为 的文本定位tikzmark。这是一个演示,描述了我想要做的事情:

在此处输入图片描述

这是我编写的代码。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\usepackage{blindtext} % not useful
\usepackage{lipsum} % not intuitive
\begin{document}


% \lipsum[5] % here I wanted to limit the lipsum text to 5 lines but couldn't manage to do it. So I commented it out.

Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla

IBM's main headquarters is located in \tikzmarknode[inner sep=2pt, draw]{falseword1}{Antarctica} IBM sold its personal computer division to \tikzmarknode[inner sep=2pt, draw]{falseword2}{Apple} in the year of 2005. Lenovo has since kept the design philosophy of IBM quite well. For instance the Lenovo's X1 series  Laptops are so aesthetic and durable as the IBM's X40 series.
\tikz\node[below of=falseword1](correctword1){New York};
\tikz\node[below of=falseword2](correctword2){Lenovo Group};

\tikz[overlay,remember picture]{\draw[latex-latex] (falseword1) -- (correctword1);}

Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla
\end{document}

如何正确地做到这一点?

答案1

您的 s 的创建tikzmarknode是正确的,但绘制部分不正确。在tikzpicture带有选项的new 中remember picture, overlay,使用普通的 TiZ 命令——在本例中是\draw

我建议你将所有这些注释都放在页边空白处并引用绝对位置,因为稍后你可能会更改段落中的文本,而你不想每次都重新定位。例如,上面的段落可能稍后Antarctica会延长几个字,而不再有空间容纳你的注释。

tikzpagenodes我使用了提供节点的包(current page text area),这样我就可以绘制到文本边缘,然后稍微超出一点。(我在下面的代码中使用了 1.5 厘米。)更改值shift将调整注释的位置。

请记住,使用时必须编译两次tikzmark

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\begin{document}

Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla

IBM's main headquarters is located in \tikzmarknode[inner sep=2pt, draw]{falseword1}{Antarctica} IBM sold its personal computer division to \tikzmarknode[inner sep=2pt, draw]{falseword2}{Apple} in the year of 2005. Lenovo has since kept the design philosophy of IBM quite well. For instance the Lenovo's X1 series  Laptops are so aesthetic and durable as the IBM's X40 series.

Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla Bla bla bla

\begin{tikzpicture}[remember picture, overlay]
\draw[blue, thick, ->](falseword1.north east)-|([shift={(1.5,-.8)}]current page text area.east|-falseword1.north east)node[below]{New York};
\draw[blue, thick, ->](falseword2.north west)-|([shift={(-1.5,-.8)}]current page text area.west|-falseword2.north west)node[below]{Lenovo Group};
\end{tikzpicture}
\end{document}

相关内容