tikzmark 和 chappg 的兼容性

tikzmark 和 chappg 的兼容性

我在文档中使用tikzmark和时遇到了一个奇怪的问题:chappg

\documentclass{scrbook} 

\usepackage{chappg}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

\chapter{Test} 

foo\tikzmark{foo}

\vspace{2cm}

bar\tikzmark{bar}

\begin{tikzpicture}[overlay,remember picture]
   \draw (pic cs:foo) -- (pic cs:bar); 
\end{tikzpicture}

\end{document}

这得出

l.21    \draw (pic cs:foo)
                           -- (pic cs:bar);

      ! Missing number, treated as zero.

第二次运行时。如果我删除文件aux并在没有的情况下编译它chappg,则一切正常。为什么会这样?

答案1

正如 Stefan 提到的his answer,似乎有问题tikzmark;在

execute at end picture={%
\ifpgfrememberpicturepositiononpage%
\edef\pgf@temp{%
\noexpand\write\noexpand\pgfutil@auxout{%
\string\savepicturepage{\pgfpictureid}{\noexpand\thepage}}}%
\pgf@temp
\fi%
},

它使用\thepage,使用 更安全。下面是更正后的版本(的定义中\value{page}还有一个,但由于这里没有用到,所以这里不相关,不过它也应该被修改):\thepage\pgfmark

\documentclass{scrbook} 

\usepackage{chappg}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\makeatletter
\tikzset{%
remember picture with id/.style={%
remember picture,
overlay,
save picture id=#1,
},
every picture/.append style={%
execute at end picture={%
\ifpgfrememberpicturepositiononpage%
\edef\pgf@temp{%
\noexpand\write\noexpand\pgfutil@auxout{%
\string\savepicturepage{\pgfpictureid}{\the\value{page}}}}%
\pgf@temp
\fi%
},
},
save picture id/.code={%
\immediate\write\pgfutil@auxout{%
\string\savepointas{#1}{\pgfpictureid}}%
},
if picture id/.code args={#1#2#3}{%
\@ifundefined{save@pt@#1}{%
\pgfkeysalso{#3}%
}{
\pgfkeysalso{#2}%
}
},
next page/.is choice,
next page vector/.initial={\pgfqpoint{0pt}{0pt}},
next page/below/.style={%
next page vector={\pgfqpoint{0pt}{-\the\paperheight}}%
},
next page/above/.style={%
next page vector={\pgfqpoint{0pt}{\the\paperheight}}%
},
next page/left/.style={%
next page vector={\pgfqpoint{-\the\paperwidth}{0pt}}%
},
next page/right/.style={%
next page vector={\pgfqpoint{\the\paperwidth}{0pt}}%
},
next page/ignore/.style={%
next page vector={\pgfqpoint{0pt}{0pt}}%
},
}
\makeatother


\begin{document}

\chapter{Test} 

foo\tikzmark{foo}

\vspace{2cm}

bar\tikzmark{bar}
\begin{tikzpicture}[overlay,remember picture]
   \draw (pic cs:foo) -- (pic cs:bar); 
\end{tikzpicture}

\end{document}

答案2

页码用于排序和引用标记位置。但是,chappg更改页码,例如从 1 更改为 1-1。会出现错误,因为那不再是一个数字。

您可以通过以下方式验证

\renewcommand*{\chappgsep}{0}

它将会起作用,因为它是数字。

无需进一步深入研究,我会说这是一个错误,因为它已经无法使用罗马页码:

\documentclass{scrbook} 
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\pagenumbering{roman}
\begin{document}
foo\tikzmark{foo}

bar\tikzmark{bar}
\begin{tikzpicture}[overlay,remember picture]
   \draw (pic cs:foo) -- (pic cs:bar); 
\end{tikzpicture}
\end{document}

这也带来了:

! Missing number, treated as zero.
<to be read again> 
                   i
l.10    \draw (pic cs:foo)
                           -- (pic cs:bar);

所以它独立于chappg

相关内容