0

If I specify the option page of \newwatermark using \pageref, I get the following error:

Package xwatermark Error: No page specifier for watermark:

How to fix that?

\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 Answer 1

1

\pageref doesn't give a number, it only prints one. You can use the refcount package:

\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}
2
  • Compiling the suggested code: ERROR: Undefined control sequence. --- TeX said --- <argument> ...e \@tempdima \@parboxrestore \color {\wmk@textcolor }\cptdimde...l.18 \end{document}. It works without the wm. Any suggestion?
    – Erwann
    Sep 11, 2018 at 19:43
  • 1
    @Erwann I shortened too much. You need a color package, e.g. xcolor (or pdfpages which would load it too). Sep 11, 2018 at 19:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .