![如果在环境中,带有跨页面边界的 tikzmark 的 Tikz 图片将不会打印](https://linux22.com/image/393842/%E5%A6%82%E6%9E%9C%E5%9C%A8%E7%8E%AF%E5%A2%83%E4%B8%AD%EF%BC%8C%E5%B8%A6%E6%9C%89%E8%B7%A8%E9%A1%B5%E9%9D%A2%E8%BE%B9%E7%95%8C%E7%9A%84%20tikzmark%20%E7%9A%84%20Tikz%20%E5%9B%BE%E7%89%87%E5%B0%86%E4%B8%8D%E4%BC%9A%E6%89%93%E5%8D%B0.png)
合并这用 s绘制括号的解决方案tikzmark
,这使它们跨越页面边界,给我带来了一个有趣的问题:如果tikzmark
位于环境中,它不会在第一页上打印垂直部分。
编辑:我正在使用来自最新更新到包含宏的 tikzmark 包\iftikzmarkoncurrentpage
,我也在下面添加了它。
% !TEX TS-program = xelatexmk
\documentclass{article}
\usepackage[paperwidth=3in,paperheight=1in]{geometry}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}
\newcounter{tikzmarklines}\setcounter{tikzmarklines}{0} %
% The following code provides the iftikzmarkoncurrentpage macro
\makeatletter
\newif\iftikzmark@
\renewcommand\iftikzmark[3]{%
\@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
#3%
}{%
#2%
}%
}%
\newcommand\iftikzmarkexists[1]{%
\@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
\tikzmark@false%
}{%
\tikzmark@true%
}%
\iftikzmark@
}%
\newcommand\iftikzmarkonpage[2]{%
\@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
\tikzmark@false
}{%
\@ifundefined{save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname}{%
\tikzmark@false
}{%
\ifnum\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname=#2\relax%
\tikzmark@true
\else
\tikzmark@false
\fi
}%
}%
\iftikzmark@
}
\newcommand\iftikzmarkoncurrentpage[1]{%
\@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
\tikzmark@false
}{%
\@ifundefined{save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname}{%
\tikzmark@false
}{%
\ifnum\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname=\the\value{page}\relax%
\tikzmark@true
\else
\tikzmark@false
\fi
}%
}%
\iftikzmark@
}
\makeatother
\tikzset{
next page=below,
brace/.style n args={2}{insert path={%
([xshift=0.15em,yshift=0.1pt+.5ex]#1) --
([xshift=-0.3pt,yshift=0.1pt+.5ex]#1) --
([xshift=-0.3pt,yshift=-0.1pt+.5ex]#2) --
([xshift=0.15em,yshift=-0.1pt+.5ex]#2) --
([xshift=0.15em,yshift=0.1pt+.5ex]#2) --
([xshift=0.3pt,yshift=0.1pt+.5ex]#2) --
([xshift=0.3pt,yshift=-0.1pt+.5ex]#1) --
([xshift=0.15em,yshift=-0.1pt+.5ex]#1) --
cycle}}}
\newif\iffirstmark
\newcommand{\linestart}{%
\stepcounter{tikzmarklines}%
\tikzmark{a\thetikzmarklines}%
\firstmarktrue
\iftikzmarkoncurrentpage{b\thetikzmarklines}%
\else
\begin{tikzpicture}[remember picture,overlay,next page=below]%
\clip (current page text area.south west) rectangle (current page text area.north east);
\fill[overlay,brace={pic cs:a\thetikzmarklines}{pic cs:b\thetikzmarklines}];
\end{tikzpicture}%
\fi
}
\newcommand{\linefinish}{%
\iffirstmark
\tikzmark{b\thetikzmarklines}%
\firstmarkfalse
\fi
\begin{tikzpicture}[remember picture,overlay]%
\clip (current page text area.south west) rectangle (current page text area.north east);
\fill[overlay,brace={pic cs:a\thetikzmarklines}{0,0}];
\end{tikzpicture}%
}
\begin{document}
% This works fine:
Text \linestart text text
\newpage
Text text \linefinish text
% But not this
\begin{center} Text \linestart text text \end {center}
\newpage
\begin{center} Text text \linefinish text \end {center}
\end{document}
第二页上只印有小钩子,而没有印到第三页的垂直线。
有任何想法吗?
答案1
您需要使 if 成为全局的:\global\firstmarktrue
并且,正如您所指出的,\global\firstmarkfalse
。
% !TEX TS-program = xelatexmk
\documentclass{article}
\usepackage[paperwidth=3in,paperheight=1in]{geometry}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}
\newcounter{tikzmarklines}\setcounter{tikzmarklines}{0} %
% The following code provides the iftikzmarkoncurrentpage macro
\makeatletter
\newif\iftikzmark@
\renewcommand\iftikzmark[3]{%
\@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
#3%
}{%
#2%
}%
}%
\newcommand\iftikzmarkexists[1]{%
\@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
\tikzmark@false%
}{%
\tikzmark@true%
}%
\iftikzmark@
}%
\newcommand\iftikzmarkonpage[2]{%
\@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
\tikzmark@false
}{%
\@ifundefined{save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname}{%
\tikzmark@false
}{%
\ifnum\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname=#2\relax%
\tikzmark@true
\else
\tikzmark@false
\fi
}%
}%
\iftikzmark@
}
\newcommand\iftikzmarkoncurrentpage[1]{%
\@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
\tikzmark@false
}{%
\@ifundefined{save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname}{%
\tikzmark@false
}{%
\ifnum\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname=\the\value{page}\relax%
\tikzmark@true
\else
\tikzmark@false
\fi
}%
}%
\iftikzmark@
}
\makeatother
\tikzset{
next page=below,
brace/.style n args={2}{insert path={%
([xshift=0.15em,yshift=0.1pt+.5ex]#1) --
([xshift=-0.3pt,yshift=0.1pt+.5ex]#1) --
([xshift=-0.3pt,yshift=-0.1pt+.5ex]#2) --
([xshift=0.15em,yshift=-0.1pt+.5ex]#2) --
([xshift=0.15em,yshift=0.1pt+.5ex]#2) --
([xshift=0.3pt,yshift=0.1pt+.5ex]#2) --
([xshift=0.3pt,yshift=-0.1pt+.5ex]#1) --
([xshift=0.15em,yshift=-0.1pt+.5ex]#1) --
cycle}}}
\newif\iffirstmark
\newcommand{\linestart}{%
\stepcounter{tikzmarklines}%
\tikzmark{a\number\value{tikzmarklines}}%
\global\firstmarktrue
\iftikzmarkoncurrentpage{b\number\value{tikzmarklines}}%
\else
\begin{tikzpicture}[remember picture,overlay,next page=below]%
\clip (current page text area.south west) rectangle (current page text area.north east);
\fill[overlay,brace={pic cs:a\number\value{tikzmarklines}}{pic cs:b\number\value{tikzmarklines}}];
\end{tikzpicture}%
\fi
}
\newcommand{\linefinish}{%
\iffirstmark
\tikzmark{b\number\value{tikzmarklines}}%
\global\firstmarkfalse
\fi
\begin{tikzpicture}[remember picture,overlay]%
\clip (current page text area.south west) rectangle (current page text area.north east);
\fill[overlay,brace={pic cs:a\number\value{tikzmarklines}}{0,0}];
\end{tikzpicture}%
}
\begin{document}
% But not this
\begin{center} Text \linestart text text \end{center}
\newpage
\begin{center} Text text \linefinish text \end{center}
% This works fine:
Text \linestart text text
\newpage
Text text \linefinish text
\end{document}