# Make sure the back cover of a book ends on a even page

I'm trying to create a back cover for a book, and I don't want to manually have to make sure it ends on a even page. However since I have different sections with different numbering (think preamble, appendix, etc) I have a hard time finding out if the current page is currently even or odd.

\cleardoublepage forces the next page to be an odd page, so it SHOULD be a simple matter to just do a \newpage and that new page would be an even page. But I can't get it to work.

The below is a minimum example that works in an environment where numbering isn't reset. But as the last numbering may not start on an odd page in my case, it doesn't seem to work all the time.

\documentclass[10pt,twoside,twocolumn,openany]{book}
\usepackage[utf8]{inputenc}
\usepackage[pages=all]{background}
\usepackage[english]{babel}
\usepackage{blindtext}

\begin{document}

\blindtext[5]

\cleardoublepage
\ifodd\value{page}
\hbox{}\newpage
\fi

\begin{titlepage}
\hbox{}
\backgroundsetup{
scale=1,
opacity=1.0,
angle=0,
color=black,
contents={%
\includegraphics[width=1.1\paperwidth]{bgcover.jpg}
}
}
\end{titlepage}

\end{document}


The lastpage package doesn't seem to work to find the total number of pages either, \pageref{LastPage} gives me the numbering of the last numbersection (e.g. III when using roman numbering). Since the appendix at that time was 3 pages long, even though the entire document was 50 pages long at the time. This due to using \setcounter{page}{1}.

Should I just try to create a counter or something that remembers, and adds together the pages before each \setcounter{page}{1} ? If then, what is the cleanest way to do that?

• cleardoublepage should put it onto an odd page, so adding a newpage after should then move it onto the next, even page. Doesn't it? – Wiebke May 22 '17 at 12:18
• I'm just playing with it ... it seems the titlepage environment is getting in the way, presumably because it's designed to put everything onto an odd page (which makes sense for a titlepage). Do you need the environment? It doesn't seem to be doing anything, even though you're setting the background color to black – Wiebke May 22 '17 at 12:33
• The changepage package offers the syntax \checkoddpage\ifoddpage...\else...\fi to accomplish these tasks. – Steven B. Segletes May 23 '17 at 12:51

To solve, I had to get rid of the titlepage environment, since it seems to put its contents always onto an odd page. To mimic the titlepage environments proper centering, I'm using the geometry package and set negative margins just before adding the backcover (see comments in code).

I always move to a fresh page, and then check if its even/odd using the ifodd command. Only if I'm on an odd page, to I issue another clearpage (note the protected space adding invisible content to the page, thus forcing the compiler to move to a new page).

edit following cfr's comment: you can use the nextpage package to take care of the manual checking for even and odd pages.

\documentclass[10pt,twoside,twocolumn,openany]{book}
\usepackage[utf8]{inputenc}
\usepackage[pages=all]{background}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{geometry}
\usepackage{nextpage}

\begin{document}
\blindtext[10]
\cleartoevenpage% this line replaces the next 5 lines
%   \clearpage% move to the next empty page
%   \ifodd\thepage% if that page is odd,
%       \thispagestyle{empty}% supress page numbering and headers for the page to be left empty
%       \ \clearpage% add a protected space to force tex to move to the next page
%   \else% do nothing
%   \fi
\newgeometry{margin=-.05\paperwidth} % setting a negative margin to make sure the figure will be centered left/right (taken care of in your MWE by the titlepage environment). Make sure the number corresponds with the width of the figure you set below
\thispagestyle{empty} % supress page numbering and headers for the back cover
\begin{figure}[p] % float environment placing the float on its own page will center top/bottom. Will go on this page, since you emptied the float queues before using the \cleardoublepage commands
\includegraphics[width=1.1\paperwidth]{example-image}
\end{figure}
\end{document}

• nextpage (I think) provides \cleartooddpage[] and \cleartoevenpage[]. Would make things easier for you. – cfr May 22 '17 at 13:36