I need automatically add a blank page (also without document header, numbering and footer) at the end of the document, if the total numbers of pages is odd. How I can do that? And preferably without using any additional package. :)
-
1Maybe the answer by Martin Scharrer to my question Ensure last page is even and blank may also be of help. – Leeser May 21 '12 at 10:18
Like this?
\documentclass[twoside]{article}
\begin{document}
one
\cleardoublepage
\end{document}
Or you could use this version
\makeatletter
\def\emptycleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\thispagestyle{empty}%
\hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
which is the same as the standard \cleardoublepage
except for the \thispagestyle{empty}%
of course you don't just have to use empty
you can have page style that inserts this page intentionally blank
or whatever else is needed.
-
2Damn! I've already reached the vote limit, but in 58min. I will upvote this as many times as I can ;-) – Gonzalo Medina May 20 '12 at 23:12
-
Thanks! @DavidCarlisle. It's a very good solution. Adding
\cleardoublepage
it works , but in the last page appears the headers, the numbering and document footer. How I can remove it? Maybe It's just a simple command! :D – osjerick May 20 '12 at 23:30 -
there's probably a qn on site somewhere that has a modified cleardoublepage with a modified page style, but I'll add it to the qn (it's generally useful not just for last page) – David Carlisle May 20 '12 at 23:52
-
Ok, Thanks!. The solution of @GonzaloMedina Works perfectly, but I wish it did not require the use of other packages. – osjerick May 20 '12 at 23:57
-
2The
emptypage
package will blank all pages added by a\cleardoublepage
command. – egreg May 21 '12 at 10:25
Original answer to Ensure last page is even and blank (now merged with this question.)
If you want to ensure even number of pages in twoside
mode you can simply add \cleardoublepage
at the end of the document, either manually or using \AtEndDocument{..}
. If you want to have the page blank you need to modify the code used by \cleardoublepage
slightly to include a \thispagestyle
:
\documentclass[twoside]{report}
%\AtEndDocument{\cleardoublepage}
\AtEndDocument{% based in \cleardoublepage
\clearpage
\ifodd\value{page}\else
\thispagestyle{empty}%
\hbox{}\newpage
\fi
}
\usepackage{lipsum}% for dummy text
\begin{document}
\lipsum[1-47]
\end{document}
This is for twoside
document only. See my answer to How to force output to a left (or right) page? for the extra code needed to behave well in oneside
documents as well.
-
-
@JosephWright sorry to be pedantic but why was my original question of a year ago "closed as exact duplicate" of this later question? Surely it should be the other way around? – Leeser Jun 4 '12 at 18:59
-
@Lesser From time to time it makes sense to 'reverse dupe' or 'reverse merge' a question. In this case, the dupe only really got flagged up up after answers had been posted to the newer one, and the way voting had worked out it made more sense to 'keep' the newer question. That's not a judgement on your question at all: it's about trying to make the most of the overall amount of information on the site. – Joseph Wright♦ Jun 4 '12 at 19:07
-
@JosephWright Ok I understand that and see the logic, but can I get my 2 points reputation back! (-2 rep due to merge) I'm languishing on low numbers so 2 points is about 0.5% to me!!!! – Leeser Jun 5 '12 at 15:57
Here's one possible option: with the help of the lastpage
package, you can check if the last page is odd or even; in the first case, add an extra page with empty
style; otherwise, do nothing:
\documentclass{article}
\usepackage{ifthen}
\usepackage{lastpage}
\usepackage{lipsum}
\AtEndDocument{%
\ifthenelse{\isodd{\pageref{LastPage}}}{\null\clearpage\thispagestyle{empty}}{}}
\begin{document}
\lipsum[1]
\end{document}
Actually, a refinement is needed to satisfy the condition for the added page (empty
page style):
\documentclass{article}
\usepackage{ifthen}
\usepackage{lastpage}
\usepackage{lipsum}
\makeatletter
\def\emptyclearpage{%
\ifvmode
\ifnum \@dbltopnum =\m@ne
\ifdim \pagetotal <\topskip
\hbox{}%
\fi
\fi
\fi
\newpage\thispagestyle{empty}
\write\m@ne{}%
\vbox{}%
\penalty -\@Mi
}
\makeatother
\AtEndDocument{%
\emptyclearpage
\ifthenelse{\isodd{\pageref{LastPage}}}{\null\emptyclearpage}{}}
\begin{document}
\lipsum[1]
\end{document}
-
Thanks! @GonzaloMedina. You know any way to do this without additional packages? – osjerick May 20 '12 at 23:03
-
1
-
@osjerick I've updated my previous answer with new code needed to satisfy the requirement of no footer/header on the added page. David's solution as it is now doen't fulfill this requirement. – Gonzalo Medina May 20 '12 at 23:32
-
Thanks! @GonzaloMedina. I run the last MWE, but this doesn't add the blank page! – osjerick May 20 '12 at 23:40
-
1@osjerick I can easily avoid using
ifthen
, but since my code requires the use the value of the page counter for the last page, I don't see at the moment an easy way to dispense with the use oflastpage
, but I'll think about it. David's answer, on the other hand, can be easily corrected to deal with the headers/footers issue. – Gonzalo Medina May 20 '12 at 23:48
You can use \AtEndDocument
to add an empty page to the end of the document if the text ends on an even page.
\documentclass{article}
\AtEndDocument{ \ifodd\value{page}\else\newpage\thispagestyle{empty} \hbox{} \fi }
\begin{document}
A \newpage B \newpage C \newpage D
\end{document}
-
If the page number is reset at an even page number (e.g. page 50 becomes new page 1), which might happen if different numbering schemes (e.g. Roman for the frontmatter) are used, or when \addtocounter{page}{...}, \setcounter or some other "nastiness" is used, a page with an even number might be on the right instead left side (or verso instead of recto). (Probably not very common, but probability is still larger zero.) – Stephen Aug 15 '11 at 18:33
If you're using emptypage
package on a twoside
document, you can have the last page even and blank using this:
\documentclass[twoside]{article}
\usepackage{emptypage}
\AtEndDocument{\clearpage\thispagestyle{empty}\null\cleardoublepage}
\begin{document}
A \newpage B % \newpage C
\end{document}