3

According to the documentation, the following should produce watermarks on every page, but it only appears on the first page:

\newwatermark*[allpages,angle=45]{watermark}

It seems xwatermark treated the doc as a single page documentation, oddpages produced the same effect as allpages and evenpages the watermark will never show up. I used \newpage in my doc and disabled page number.

And if I move text mark to background, it also doesn't appear at all:

\newwatermark[allpages,angle=45]{watermark}

However draftwatermark successfully printed watermark on all pages. But I need some features in xwatermark so need to make it work.


Edit: It's a rather large file, base configurations for this tex file as following. I think it should included all samples that might concern the question.

\documentclass[10pt]{article}

% encoding
\usepackage[T1]{fontenc}

% watermark
\usepackage{xwatermark}
\usepackage{textcomp} 

\usepackage{afterpage}


% line spacing
\usepackage{setspace}

% use color in latex
\usepackage{xcolor}

% character encoding
\usepackage[utf8]{inputenc}
\usepackage{CJKutf8}

% adjust the page margins
\usepackage[scale=0.75,a4paper,bindingoffset=0.2in,left=0.5in,right=1in,top=1in,bottom=1in,footskip=.25in]{geometry}

% define page header and footer
\usepackage{fancyhdr}
\pagestyle{fancy}

\fancyhf{}
\renewcommand{\headrulewidth}{\iffloatpage{0pt}{0pt}}
\renewcommand{\footrulewidth}{\iffloatpage{0pt}{0pt}}

% define page style
\fancypagestyle{summary}{
  \fancyhf{} % Clear all headers/footers
  \renewcommand{\headrulewidth}{4mm}
  \fancyhead[L]{% header left-aligned
    \fontsize{12}{14} \selectfont
    \textcolor{grey}{}\vspace{1em}
  }
  \renewcommand{\headrule}{\hbox to\headwidth{%
    \color{green}\leaders\hrule height \headrulewidth\hfill}}
  \renewcommand{\footrulewidth}{0pt}% No footer rule
}

% set watermark
\newwatermark*[allpages,angle=45]{watermark}

\begin{document}
\begin{CJK*}{UTF8}{gbsn}

page 1 ...
\newpage

page 2 ...
\newpage

\clearpage\end{CJK*}
\end{document}

Edit: @steve in comments compiled a file with watermarks on both pages, but I didn't. The sencond page has no watermark. I'm working on Ubuntu.

I found a historical problem some years ago here: xwatermark allpages does not work on Ubuntu but comments saying it shouldn't matter with operating system. While it demonstrated to be.

knh190
  • 153
  • One really has to provide a small working example that demonstrates the problem, rather than code snippets, so that we can see what document class is being used, what packages are loaded and in what order, etc. Welcome to the site. Please edit your question. – Steven B. Segletes Oct 14 '16 at 12:24
  • @StevenB.Segletes it's a large tex file, I added configurations to see if there included clues. – knh190 Oct 14 '16 at 12:39
  • Thanks for providing the MWE. I have edited your question so that it actually compiles and provides output. However, I get a watermark on both pages, when doing so. Can you confirm that you do not?? – Steven B. Segletes Oct 14 '16 at 12:54
  • 1
    @StevenB.Segletes yeah. I produced the file and the second page has no watermark. Seems os related. I'm using Ubuntu. – knh190 Oct 14 '16 at 12:58
  • 1
    It is extremely unlikely that it is 'os related'. But, for what it's worth, using the above file, I get a watermark on both pages on Ubuntu 14.04.5 (the more salient information is: TeX Live 2016 and xwatermark.sty 2012/10/23 v1.5.2d). If you really aren't getting a watermark on both pages, add the line \listfiles to your preamble, compile, check the end of the .log file and post the file versions of the relevant packages. – jon Oct 14 '16 at 19:19
  • @jon TeX Live 2015/Debian. xwatermark is the same version as yours. But after I did an upgrade from apt source, it's fixed. I didn't notice which one was upgraded (not tex live nor xwatermark), apt upgrade log showed no package related to tex live changed. – knh190 Oct 15 '16 at 09:33
  • For furthur good, I posted latest attempt log in gist: https://gist.github.com/KHN190/33a76817d49ef96a0f51af15ea8a92fb – knh190 Oct 15 '16 at 09:40
  • 1
    Well, a lot of packages have changed between TL2015 and TL2016, but clearly not xwatermark. However, other packages have changed since TL2015 (some are loaded behind the scenes). There also can be (resolvable) conflicts between xwatermark and geometry: if interested, see §.9 of the xwatermark package for more details. – jon Oct 15 '16 at 16:09

1 Answers1

1

It seems to be caused by the broken way of getting the lastpage number in xwatermark package.

The internal macro \lastdocpage is used to mark the last page number. And if you print the macro you will find it always be 1.

So here is a work around by using additional packages to find the last page.

\documentclass{article}

\usepackage[2020-02-02]{latexrelease} % <- for avoidance of incompatibility % more at: https://tex.stackexchange.com/questions/566088

\usepackage{xcolor} \usepackage[printwatermark]{xwatermark} \newwatermark[allpages,textmark={All pages},angle=0,scale=2,ypos=0]{} \newwatermark[oddpages,textmark={Odd pages},angle=0,scale=2,ypos=50]{} \newwatermark[evenpages,textmark={Even pages},angle=0,scale=2,ypos=50]{}

% fix \lastdocpage \usepackage{lastpage} \usepackage{refcount} \renewcommand{\lastdocpage}{\getpagerefnumber{LastPage}}

\begin{document} \setcounter{page}{100} \null\newpage \null\newpage \null\newpage \null \end{document}