Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Follow-up question to Hiding watermark for first page?.

I have recently learned about \lastdocpage (from the previous question), but is there a way to refer to two pages prior to \lastdocpage? To understand the context, the watermark from the previous question should last from pages 2 to two pages prior to the end of the document.

MWE:

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{tikz}
\usepackage[version=3]{mhchem}
\usepackage [english]{babel}
\usepackage[printwatermark]{xwatermark}
\newwatermark*[pages=2-\lastdocpage,color=gray,angle=0,scale=1,xpos=46,ypos=-134]{\footnotesize Copyright \textcopyright\:2014 by some company.}
\begin{document}
Stuff
\newpage 
More stuff
\end{document}

In this MWE, the watermark is on pages 2 to \lastdocpage. I have tried \pages=2-{\lastdocpage-2}but this did not work.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

According to the manual of xwatermark you should be able to write

pages=2-{\lastdocpage-2}

Indeed the manual contains the example

pages={\lastdocpage-2}-\lastdocpage

However, while the last version works, the first throws an error. Explicitly forcing it to a number as follows does however work:

pages=2-{\number\numexpr\lastdocpage-2}

So a complete document would be:

\documentclass[12pt]{article}

\usepackage[margin=2cm]{geometry}
\usepackage{tikz}
\usepackage[version=3]{mhchem}
\usepackage [english]{babel}
\usepackage[printwatermark]{xwatermark}

\newwatermark*[pages=2-{\number\numexpr\lastdocpage-2},color=gray,angle=0,scale=1,xpos=46,ypos=-134]{\footnotesize Copyright \textcopyright\:2014 by some company.}

\begin{document}
Stuff
\newpage 
More stuff
\newpage
Third page
\newpage
Fourth page

\end{document}

[The above requires you have a standard modern tex engine that includes the etex features.]

share|improve this answer
    
Your version is definitely much easier ;-) –  Christian Hupfer Jul 15 at 8:03

You have to save the value of \lastdocpage to a counter and decrease the counter by the appropiate value, i.e. in this case by two. Afterwards it is possible to use the counter value as end limit of the watermarks.

To use the counter value of lastwatermarkpage, it is possible either

  • saying \thelastwatermarkpage
  • \number\value{lastwatermarkpage} which guarantess, that the output is a number, whereas \thelastwatermark is a command, which can basically redefined to do anything else, so usage is discouraged.

I have used a \forloop to generate some dummy pages. In the production run, this can be removed of course, as well as the loopcounter definition.

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{tikz}
\usepackage[version=3]{mhchem}
\usepackage [english]{babel}
\usepackage[printwatermark]{xwatermark}

\usepackage{forloop}

\newcounter{loopcounter}

\newcounter{lastwatermarkpage}
\setcounter{lastwatermarkpage}{\lastdocpage}
\addtocounter{lastwatermarkpage}{-2}%

\newwatermark*[pages=2-{\number\value{lastwatermarkpage}},color=gray,angle=0,scale=1,xpos=46,ypos=-134]{\footnotesize Copyright \textcopyright\:2014 by some company.}
\begin{document}
\forloop{loopcounter}{1}{\number\value{loopcounter} < 22}{%
Some stuff
\clearpage

}%
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.