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 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. :)

share|improve this question
1  
Maybe 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
    
Thanks! @Leeser. –  OSjerick May 21 '12 at 13:08

5 Answers 5

up vote 30 down vote accepted

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.

share|improve this answer
2  
Damn! 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
2  
The emptypage package will blank all pages added by a \cleardoublepage command. –  egreg May 21 '12 at 10:25

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}
share|improve this answer
    
Thanks! @GonzaloMedina. You know any way to do this without additional packages? –  OSjerick May 20 '12 at 23:03
1  
@osjerick see David's answer! –  Gonzalo Medina May 20 '12 at 23:12
    
@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 of lastpage, 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

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.

share|improve this answer
    
Martin's answer works a treat and has been implemented into the class file, Cheers, leeser –  Leeser Jun 2 '11 at 16:15
    
@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

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}
share|improve this answer
    
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}
share|improve this answer
    
Welcome to TeX.SX! –  Daniel Oct 25 '13 at 11:38
    
Thank you very much! –  Shiva Oct 25 '13 at 13:20

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.