I am experiencing an issue with page numbering when compiling an Rnw file using different versions of LaTeX. Here’s a summary of the problem:
Older LaTeX Version (MiKTeX-pdfTeX 2.9.6499):
- First page: No page number.
- Second page: Page number 2.
- Last page: Page 18 (landscape orientation).
Newer LaTeX Version (MiKTeX-pdfTeX 4.1):
- First page: No page number
- Second page: No page number
- Third page: Page number 2
- Last page: Page 18 (It is empty and in portrait orientation, whereas all pages should be in landscape orientation.)
It seems that in the newer version, the first page is considered a cover page and is not taken into account in the page numbering, resulting in discrepancies with the expected page numbering sequence.
I suspect the problem is also related to the {everypage}
package, which is now in legacy status.
I aim to achieve consistent page numbering behavior across different LaTeX versions. Ideally, I want the output to match the behavior of the older LaTeX version.
Below is a simplified version of my Rnw file:
documentclass[a4paper]{article}
usepackage{fontspec}
usepackage{pdfpages}
usepackage{hyperref}
usepackage{lastpage}
usepackage[paperwidth=8.27in, paperheight=11.69in, left=0.5in, right=0.5in, top=0.72in, bottom=0.75cm, includefoot, heightrounded, footskip=0.2in]{geometry}
usepackage[absolute,overlay]{textpos}
usepackage{pdflscape}
usepackage{everypage}
setmainfont[Scale=0.878]{Segoe UI}
definecolor{iblue}{RGB}{43,72,148}
% Define the position of the page number in the right margin
newcommand{rightpagenumber}{
begin{textblock*}{1in}[1,0](paperwidth+0.65in,5.55in)
rotatebox{90}{bfseries color{iblue} thepage of pageref{LastPage}}
end{textblock*}
}
% Add the page number to every page except the first one
newcounter{pagecount}
AddEverypageHook{
stepcounter{pagecount}
ifnumvalue{pagecount}>1
rightpagenumber
fi
}
begin{document}
includepdf[pages=-, landscape, pagecommand={thispagestyle{empty}hypertarget{page.thepage}{}}]{report_1.pdf}
includepdf[pages=-, landscape, pagecommand={thispagestyle{empty}hypertarget{page.thepage}{}}]{report_2.pdf}
includepdf[pages=-, landscape, pagecommand={thispagestyle{empty}hypertarget{page.thepage}{}}]{report_3.pdf}
end{document}
All imported PDF documents are copies of the document created using this code:
documentclass[a4paper]{article}
usepackage{fontspec}
usepackage{lipsum}
usepackage[paperwidth=8.27in, paperheight=11.69in, left=0.5in, right=0.5in, top=0.72in, bottom=0.75cm, includefoot, heightrounded, footskip=0.2in]{geometry}
usepackage{fancyhdr}
usepackage{pdflscape}
setmainfont[Scale=0.878]{Segoe UI}
% Configure fancyhdr to clear the default footer
pagestyle{fancy}
fancyhf{} % Clear all header and footer fields
renewcommandheadrulewidth{0pt}
renewcommandfootrulewidth{0pt}
% Custom command to insert Lorem Ipsum paragraphs with blank lines in between
newcommand{lipsumwithpar}[2]{%
foreach i in {#1,...,#2} {%
lipsum[i]vspace{1baselineskip}
}%
}
usepackage{pgffor}
begin{document}
begin{landscape}
lipsumwithpar{1}{57}
end{landscape}
end{document}