跨多个页面绘制 TikZ 箭头

跨多个页面绘制 TikZ 箭头

我想在边注之间添加箭头,我已通过\tikzmarknode(图 1)实现了此目的。但如果一个标记位于另一页上,则无法实现(图 2)。

我想要的是一条连续的线一直延伸到页面末尾,然后重新出现在下一页的顶部(图 3)。

在此处输入图片描述 在此处输入图片描述 在此处输入图片描述

梅威瑟:

\documentclass[10pt,oneside]{scrbook}
\usepackage{lipsum}
\usepackage[left=32.5mm, right=22.5mm, top=25mm, bottom=20mm, marginparsep=3mm]{geometry}
\usepackage{tikz}
    \usetikzlibrary{tikzmark}
\usepackage{marginnote}
\renewcommand*{\marginfont}{\footnotesize\itshape}

\begin{document}

\marginnote{\tikzmarknode{a}{Thermoplast}}
\lipsum[1]
\marginnote{\tikzmarknode{b}{teilkristallin}}
\lipsum[1]
\marginnote{\tikzmarknode{c}{aliphatisch}} 
\begin{tikzpicture}[remember picture, overlay, shorten >=1.5mm, shorten <=1.5mm,->]
    \draw ([xshift=10pt]a.south west) to ([xshift=10pt]b.north west);
    \draw ([xshift=10pt]b.south west) to ([xshift=10pt]c.north west);
\end{tikzpicture}
% \lipsum[1-6]    % Works fine
\lipsum[1-7]    % Doesn't work
\marginnote{\tikzmarknode{d}{aliphatisch}} 
\begin{tikzpicture}[remember picture, overlay, shorten >=1.5mm, shorten <=1.5mm,->]
    \draw ([xshift=10pt]c.south west) to ([xshift=10pt]d.north west);
\end{tikzpicture}

\end{document}

答案1

tikzmark库带有检查\iftikzmarkoncurrentpage。这使我们能够区分情况

  1. 当前页面上没有任何节点(当前页面可能位于两个带有后续标记的页面之间,并且这两个页面需要连接),
  2. 当前页面上的第一个节点,
  3. 当前页面上的第二个节点,
  4. 两个节点位于同一页面上。

这些情况在宏中有所区别\ConnectTikZmarknodes,宏还可以跨分页符连接节点。它用于eso-pic避免要求用户在多个页面上添加宏。由于附带的良好检查,tikzmark可以\ConnectTikZmarknodes在实际定义节点之前添加(并且,如果连接跨多个页面,也是必要的)。

\documentclass[10pt,oneside]{scrbook}
\usepackage{lipsum}
\usepackage[left=32.5mm, right=22.5mm, top=25mm, bottom=20mm, marginparsep=3mm]{geometry}
\usepackage{tikzpagenodes}
\usepackage{eso-pic}
\usetikzlibrary{tikzmark}
\usepackage{marginnote}
\renewcommand*{\marginfont}{\footnotesize\itshape}
\makeatletter
\newcommand\PageOfTikzmark[1]{%
\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname}
\makeatother
\newcommand{\ConnectTikZmarknodes}[3][]{\AddToShipoutPictureFG{%
\begin{tikzpicture}[remember picture, overlay, shorten >=1.5mm, 
    shorten <=1.5mm,#1]
\iftikzmark{#2}{\edef\pageA{\PageOfTikzmark{#2}}}{\edef\pageA{-1}}% 
\iftikzmark{#3}{\edef\pageB{\PageOfTikzmark{#3}}}{\edef\pageB{-1}}% 
\iftikzmarkoncurrentpage{#2}
\edef\myflag{1}%
\else
\edef\myflag{0}%
\fi 
\iftikzmarkoncurrentpage{#3}
\edef\myflag{\the\numexpr\myflag+2}%
\fi 
\ifcase\myflag
\or
 \draw[-] ([xshift=10pt]#2.south west)
     to ([xshift=10pt]#2.south west|-current page text area.south);
\or
 \draw[->] ([xshift=10pt]#3.north west|-current page text area.north) 
    to ([xshift=10pt]#3.north west);  
\or
 \draw[->] ([xshift=10pt]#2.south west)
     to ([xshift=10pt]#3.north west);
\fi
\ifnum\value{page}>\pageA
\ifnum\value{page}<\pageB
 \draw ([xshift=20pt]current page text area.north east) to
 ([xshift=20pt]current page text area.south east);
\fi
\fi
\end{tikzpicture}}}
\begin{document}

\marginnote{\tikzmarknode{a}{Thermoplast}}
\lipsum[1]
\marginnote{\tikzmarknode{b}{teilkristallin}}
\ConnectTikZmarknodes{a}{b}
\lipsum[1]
\marginnote{\tikzmarknode{c}{aliphatisch}} 
\ConnectTikZmarknodes{b}{c}
\lipsum[1-7]    % works fine
\marginnote{\tikzmarknode{d}{aliphatisch}} 
\ConnectTikZmarknodes{c}{d}
\ConnectTikZmarknodes{d}{e}
\lipsum[1-23]    
\marginnote{\tikzmarknode{e}{unproblematisch}} 
\end{document}

在此处输入图片描述

相关内容