简洁地绘制从 tikzmarknode 到节点的路径并使用加号线到操作

简洁地绘制从 tikzmarknode 到节点的路径并使用加号线到操作

我正在编辑一篇 50 页长的文章,其中我想使用标记文本tikzmarknode,然后从中绘制一条路径到这样的节点:

在此处输入图片描述

我写了这个代码。

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

\lipsum[1]\tikzmarknode[inner sep=2pt,draw]{surname}{\mbox{Kennedy}}\lipsum[1]

\vspace{25pt}

\lipsum[1]

\begin{tikzpicture}[remember picture, overlay]
\draw[blue,thick,->](surname.south west) -| ([shift={(-1.3,-5.2)}]surname.south west) -- ([shift={(0.5,-5.2)}]surname.south west) 
% \draw[blue,thick,->](surname.south west) -| (-1.3,-5.2) -- (1.8,0)  % That looks fine but it doesn' give the expected result
% \draw[blue,thick,->](surname.south west) -| (-1.3,-5.2) +- (1.8,0)  % That's intuitive but it doesn't  even compile
% \draw[blue,thick,->](surname.south west) -| ([shift={(-1.3,-5.2)}]surname.south west) -- (1.8,0)  % That still involves repetition  and doesn't give the expected output
node [right, draw]{\footnotesize John Fitzgerald Kennedy, the 35th president of the USA from 1961 to 1963};

\end{tikzpicture}
\end{document}

尽管代码重复,我还是设法绘制了路径。为了消除这些重复,我重写了路径,代码中给出了我重写的 3 次尝试。但都没有成功。其中一次给出了例如以下输出:

在此处输入图片描述

我查看了 TikZ 文档,但很难从中消化这些具体信息。我查看了这个类似的问题告诉 TikZ 通过线到操作继续先前绘制的路径?但它不符合我的问题的具体结构。

如何以最简洁的方式编写该路径代码?原因:我将在我编辑的文章中数十次使用此代码。

可选/相关问题如何使用加号 line-to 操作?它可能在某处有文档记录,但由于它是一个没有名称的符号,因此在 TikZ 文档中识别它或在 Internet 上搜索它并不容易。

答案1

我认为您正在寻找以下内容:

带有 --++ 和 |-++ 的路径

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

\lipsum[1]\tikzmarknode[inner sep=2pt,draw]{surname}{\mbox{Kennedy}}\lipsum[1]

\vspace{25pt}

\lipsum[1]

\begin{tikzpicture}[remember picture, overlay]
\draw[blue,thick,->](surname.south west) --++ (-1.5,0) |-++ (1.5,-5) node [right, draw]{\footnotesize John Fitzgerald Kennedy, the 35th president of the USA from 1961 to 1963};

\end{tikzpicture}
\end{document}

快速说明

--++ (-1.5,0)表示“从当前点向左边1.5cm的点绘制,并将当前点放在该位置”;

|-++ (1.5,-5)意思是“从当前点向右 1.5 厘米、向下 5 厘米的点绘制,先垂直绘制,再水平绘制,并将当前点放在此位置”。

相关内容