5

I would like to know if there is a code on preambule wich allows me to alternate 2 images, placing one of them as background on even numbered pages, and the other one the odd numbered pages.

Actually I have one image for every page.

I'm using in my preambule:

\usepackage[scale=0]{background}
\SetBgScale{1}
\SetBgAngle{0}
\SetBgOpacity{1}
\SetBgVshift{-7.1mm}
\SetBgContents{\includegraphics{image/hkbg.eps}}

And for the fisrt page, I have this line to prevent my background to appear in it:

\NoBgThispage
5

You can use ifoddpage package:

\documentclass[12pt]{book}
\usepackage{background}
\usepackage{ifoddpage}
\usepackage{kantlipsum}
\backgroundsetup{
scale=1,
opacity=0.3,
angle=0,
color=black,
contents={%
 \checkoddpage
  \ifoddpage
   \includegraphics[width=\paperwidth]{example-image-a}
  \else
   \includegraphics[width=\paperwidth]{example-image-b}
  \fi
}
}

\begin{document}
  \NoBgThispage
  \kant[1-50]
\end{document}

enter image description here

If you don't want to use any extra package simply do this:

\backgroundsetup{
scale=1,
opacity=0.3,
angle=0,
color=black,
contents={%
 \ifodd\value{page}
   \includegraphics[width=\paperwidth]{example-image-a}
  \else
   \includegraphics[width=\paperwidth]{example-image-b}
  \fi
}
}

and remove \usepackage{ifoddpage}.

  • It works with the `\usepackage{ifoddpage}', without it doesn't. – hkviktor Aug 10 '14 at 15:30
  • @hkviktor The second snippet works without ifoddpage. It works for me. :-) – user11232 Aug 10 '14 at 15:35
  • Well, maybe I have some problems, because to me, it doesn't. Thanks anyway, the package works very well – hkviktor Aug 10 '14 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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