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.

I am totally new to LaTeX and right now I'm trying to find out how everything works. For the following code I get a background picture only on the first page although I want to have it on all odd pages. Additionally I get an error stating:

Undefined control sequence: \AddEverypageHook

This is my code:

\documentclass[a4paper]{report}
\usepackage[english]{babel} 
\usepackage{lipsum}
\usepackage{ifthen}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{eso-pic}

\newcommand\BackgroundPic{
\put(-4,0){
\parbox[b][\paperheight]{\paperwidth}{%
\vfill
\centering
\includegraphics[width=\paperwidth,height=\paperheight,
keepaspectratio]{background.jpg}%
\vfill
}}}

\makeatletter
\AddEverypageHook{%
\ifthenelse{\isodd{\value{page}}}%
  {}%
  {\AddToShipoutPicture*{\BackgroundPic}}%
  }
\makeatother

\begin{document}


\title{The Triangulation of Titling Data in
       Non-Linear Gaussian Fashion via $\rho$ Series}
\date{October 31, 475}
\author{John Doe\\ Magic Department, Richard Miles University
        \and Richard Row, \LaTeX\ Academy}
\maketitle
\blinddocument
\end{document}

It would be nice if you could help me with this and explain what is going wrong here. Thanks in advance.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

The eso-pic package does not provide \AddEverypageHook, hence the "Undefined control sequence" error. The latter is provided by the everypage package. However, since eso-pic loads atbegshi by default, you can use the functionality provided by it to tap into the page output routine.

It seems like you're after printing some background image on every odd/even page of your document. The following does that:

enter image description here

\documentclass[a4paper]{report}
\usepackage[english]{babel}% http://ctan.org/pkg/babel
%\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{ifthen}% http://ctan.org/pkg/ifthen
\usepackage{blindtext}% http://ctan.org/pkg/blindtext
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{eso-pic}% http://ctan.org/pkg/eso-pic

\newcommand\BackgroundPic{%
  \put(-4,0){%
    \parbox[b][\paperheight]{\paperwidth}{%
      \vfill
      \centering
      \includegraphics[width=\paperwidth,height=\paperheight,keepaspectratio]{tiger}%
      \vfill
  }}}

%\makeatletter
\AtBeginShipout{%
  \ifthenelse{\isodd{\value{page}}}%
    {}%
    {\AddToShipoutPictureBG*{\BackgroundPic}}%
}
%\makeatother

\begin{document}


\title{The Triangulation of Titling Data in
       Non-Linear Gaussian Fashion via $\rho$ Series}
\date{October 31, 475}
\author{John Doe\\ Magic Department, Richard Miles University
        \and Richard Row, \LaTeX\ Academy}
\maketitle
\blinddocument
\end{document}

Here are some further considerations:

  • To place an image in the "background layer", eso-pic offers \AddToShipoutPictureBG while \AddToShipoutPictureFG prints it in the "foreground layer". Each have a starred variant pertaining to only that page it's called on. There is no \AddToShipoutPicture (without BG or FG).

  • The picture addition is based on \value{page}, so any command that influences page numbering has an effect on the placement (like your title).

share|improve this answer
    
thanks a lot for the fast answer. This helped me a lot :). –  Jean-Claude Feb 18 '12 at 23:03

Here is a solution by xwatermark package.

\documentclass{article}
\makeatletter
\usepackage[dvipsnames]{xcolor}
%\usepackage[colorlinks,pdfview=FitB]{hyperref}
\usepackage[printwatermark]{xwatermark}[2012/02/01]
% Local watermark locations:
\watermarkpaths{{./}{./Graphics/}}
% \newwatermark has a key-value interface. There are many more keys; see the 
% package documentation. 'oddpages' means 'put watermarks on odd pages only'.
\newwatermark[
  oddpages,coordunit=pc,fontfamily=put,textcolor=BurntOrange,fontsize=5cm,
  textalign=center,textangle=45,picangle=0,textxpos=-4,textypos=4,picxpos=0,
  picypos=0,picontoptext,picbb=127 203 527 672,picscale=.6,picfile=mindmap1,
  picfileext=pdf
]{MIND}
% Get the dimensions of the graphics 'comet1':
\xwmgetpicdim[scale=.5,viewport=20 21 590 400]{comet1}
% Put 'comet1' on odd pages, at the given positons:
\repeatwatermarks[Page=\thepage]{%
  oddpages,coordunit=pc,picbb=20 21 590 400,picscale=.5,picfile=comet1,
  textontoppic,fontsize=2.5cm,textcolor=white
}{%
  picxpos=-.5\paperwidth+\xwmwdofpic/2,picypos=-.5\paperheight+\xwmtothtofpic/2,
  textxpos=-.5\paperwidth+\xwmwdofpic/2,textypos=-.5\paperheight+\xwmtothtofpic/2;
  picxpos=-.5\paperwidth+\xwmwdofpic/2,picypos=.5\paperheight-\xwmtothtofpic/2,
  textxpos=-.5\paperwidth+\xwmwdofpic/2,textypos=.5\paperheight-\xwmtothtofpic/4;
  picxpos=.5\paperwidth-\xwmwdofpic/2,picypos=-.5\paperheight+\xwmtothtofpic/2,
  textxpos=.5\paperwidth-\xwmwdofpic/2,textypos=-.5\paperheight+\xwmtothtofpic/2;
  picxpos=.5\paperwidth-\xwmwdofpic/2,picypos=.5\paperheight-\xwmtothtofpic/2,
  textxpos=.5\paperwidth-\xwmwdofpic/2,textypos=.5\paperheight-\xwmtothtofpic/4
}

\begin{document}
xx
\newpage
yy
\newpage
zz
\newpage
aa
\newpage
bb
\end{document}

The image shows only page 1 of the output.

enter image description here

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.