![使用 xwatermark 和 pageref](https://linux22.com/image/381905/%E4%BD%BF%E7%94%A8%20xwatermark%20%E5%92%8C%20pageref.png)
如果我指定使用page
选项,我会收到以下错误:\newwatermark
\pageref
包 xwatermark 错误:没有水印的页面说明符:
如何修复?
\documentclass{article}
\usepackage{afterpage}
\usepackage{xwatermark} %[printwatermark]{xwatermark}
\usepackage{pdfpages}
\begin{document}
\verb|\pageref{sec:foo}| \pageref{sec:foo} % 3, as expected
\newwatermark*[
% TODO replace
page=3
% by:
% \pageref{sec:foo} % Package xwatermark Error: No page specifier for watermark:
]{Watermark}
\tableofcontents
\clearpage
\vspace*{\fill}
{\LARGE \begin{center}Bar\end{center}}
\vspace*{\fill}
\clearpage
\csname phantomsection \endcsname % hyperref
%\afterpage{
\addcontentsline{toc}{section}{Foo}
%}
\label{sec:foo}
\includepdf[pages={1-}]{/home/er/Documents/essential/dev/LaTeX/toy/misc/huge/Foo.pdf} % Foo.pdf is a one page pdf
\end{document}
答案1
\pageref 不会给出数字,它只会打印一个。您可以使用 refcount 包:
\documentclass{article}
\usepackage{xwatermark} %[printwatermark]{xwatermark}
\usepackage{pdfpages}
\usepackage{refcount}
\begin{document}
\verb|\pageref{sec:foo}| \pageref{sec:foo} % 3, as expected
\newwatermark*[
page=\getpagerefnumber{sec:foo}
]{Watermark}
\newpage
\section{blub}\label{sec:foo}
\end{document}