\numexpr
divisions round, so they are not so good in this case:
\documentclass{article}
\usepackage{refcount,lastpage}
\usepackage{kantlipsum}
\makeatletter
\newcommand{\checkmultipleoffour}{%
\count@=\getpagerefnumber{LastPage}%
\@tempcnta=\count@
\divide\@tempcnta by 4
\multiply\@tempcnta by 4
\count@=\numexpr\count@-\@tempcnta\relax
\ifnum\count@>0
\pagestyle{empty}
\loop\ifnum\count@<4
\null\clearpage
\advance\count@\@ne
\repeat
\fi
}
\makeatother
\AtEndDocument{\checkmultipleoffour}
\begin{document}
\kant[1-11] % for a 4 page document
% \kant[1-15] % for a 5 page document
\end{document}
The same in expl3
syntax:
\documentclass{article}
\usepackage{xparse}
\usepackage{refcount,lastpage}
\usepackage{kantlipsum}
\ExplSyntaxOn
\NewDocumentCommand{\checkmultipleoffour} { }
{
\prg_replicate:nn
{ \int_mod:nn { 4 - \int_mod:nn { \getpagerefnumber{LastPage} } { 4 } } { 4 } }
{ \thispagestyle{empty}\null\clearpage }
}
\ExplSyntaxOff
\AtEndDocument{\checkmultipleoffour}
\begin{document}
\kant[1-11] % for a 4 page document
% \kant[1-15] % for a 5 page document
\end{document}
With \frontmatter
and \mainmatter
the situation is a bit more complicated.
\documentclass{book}
\usepackage{xparse}
\usepackage{refcount,lastpage,etoolbox}
\usepackage{kantlipsum}
\makeatletter
\patchcmd\mainmatter{\cleardoublepage}
{%
\clearpage\edef\@currentlabel{\number\numexpr\arabic{page}\ifodd\arabic{page}+1\fi\relax}%
\label{LastFrontmatterPage}%
\cleardoublepage
}{}{}
\makeatother
\ExplSyntaxOn
\cs_new:Npn \egreg_int_coremainder:nn #1 #2
{
\int_mod:nn { #2 - \int_mod:nn { #1 } { #2 } } { #2 }
}
\NewDocumentCommand{\checkmultipleoffour} { O{0} }
{
\prg_replicate:nn
{
\egreg_int_coremainder:nn { #1 + \getrefnumber{LastFrontmatterPage} + \getpagerefnumber{LastPage} } { 4 }
}
{ \thispagestyle{empty}\null\clearpage }
}
\ExplSyntaxOff
\AtEndDocument{\checkmultipleoffour}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{A}
\kant[1-11]
\end{document}
The \checkmultipleoffour
has also an optional argument where specifying possible pages before \frontmatter
(an unnumbered frontispiece, for instance).
Note that a couple of LaTeX runs may be needed, because these macros require the \label
-\ref
system to synchronize.
You could use \clearpage
after your first group of tables (it should not make a blank page) or just make the last of the first group bigger so the second group has to start on a new page for example
\begin{table}[p]
\begin{tabular}...
\caption{...}
\vspace{.4\textheight}
\end{table}
Best Answer
Issue
\clearpage
at the end of the document; then check whether the page number is odd and do nothing in this case, otherwise eject an empty page; the following code in the document preamble will do:This works independently of the
oneside
ortwoside
option. In the latter caseis sufficient (as stated by Ulrike).