Call the last page before \includepdf

lastpagepagesltspdfpages

I have a proposal letter (my latex is in article though)with 6 pages. I have a header that says page # of ##. # is the page number and ## is the total number of pages. So the last page should be page 6 of 6. It works well with lastpage package. Until…

I want to add a two page terms and conditions as an attachment at the end and I am using \includepdf. However, my header count on the 6th page (last page of the proposal) changes to page 6 of 8.

Is there any way to call the 6th page as the last page for page counting.

Best Answer

Option 1 Instead of the lastpage package you can use pageslts which allows for different numbering schemes with a nice feature that might be useful in this case. (Because I guess the added document shouldn't start again with page number 1.)

When the page numbering scheme is changed the page numbers are reset. So the appendix will be numbered with roman numbers starting with i, ii, ... while the last page of the main document will remain equal to 6 and the last page of the appendix will be ii.

The file TermsConditions.tex is typeset without page numbers and included using the package pdfpages. The pages will be numbered by the main document. (By using a width=\textwidth the font will be very small as it should be for Terms an Conditions ;-))

a

This is main.tex

%% File main.tex

\documentclass[12pt,a4paper]{article}

\usepackage{kantlipsum}

\usepackage[pagecontinue=false,alphMult=ab,AlphMulti=AB,    fnsymbolmult=true,romanMult=true,RomanMulti=true]{pageslts}

\usepackage{fancyhdr}
\fancypagestyle{fancy}{% normal pages
    \fancyhf{} % clear all
    \fancyfoot[C]{\thepage\ of \lastpageref{pagesLTS.arabic}}%
    \renewcommand{\headrulewidth}{0pt}% no rule 
}

\fancypagestyle{xtra}{% for appendix
    \fancyhf{} % clear all
    \fancyfoot[C]{\thepage\ of \lastpageref{pagesLTS.roman}}%
    \renewcommand{\headrulewidth}{0pt}% no rule 
}

\pagestyle{fancy}   

\usepackage[left=5.00cm, right=5.00cm, top=4.00cm, bottom=5.00cm]{geometry}

\usepackage[final]{pdfpages}

\title{A proposal}

\begin{document}
    \pagenumbering{arabic}
    \maketitle
    
    \kant[1-12] % make six pages
    
    \newpage % starts a new numbering scheme last page is reset
    \pagenumbering{roman}
    \pagestyle{xtra}
    
    \includepdf[pages=-,pagecommand={ },width=\textwidth]{TermsConditions.pdf}      
    
\end{document}

This is TermsConditions.tex

%%% File TermsConditions.tex

\documentclass[12pt,a4paper]{article}
\usepackage{kantlipsum}
\usepackage[left=3.00cm, right=3.00cm, top=4.00cm, bottom=3.00cm]{geometry}

\usepackage{fancyhdr}
\fancypagestyle{plain}{\fancyhf{}\renewcommand{\headrulewidth}{0pt}}

\title{Terms and Conditions}

\pagestyle{empty}

\begin{document}
    
    \maketitle  

    \kant[1-4]  % make two pages
\end{document}

If you want to keep the same geometry in both documents use in TermsConditions.tex

\usepackage[left=5.00cm, right=5.00cm, top=4.00cm, bottom=5.00cm]{geometry}

(the same setup used in main.tex) and

 \includepdf[pages=-,pagecommand={ }]{TermsConditions.pdf}  

in the main.tex

b

Option 2 If you want to keep lastpage, the following code will achieve the same result by adding the additional document as an appendix.

%% File main.tex  version 2

\documentclass[12pt,a4paper]{article}

\usepackage{kantlipsum}

\usepackage{lastpage}

\usepackage{fancyhdr}
\fancypagestyle{fancy}{% normal pages
    \fancyhf{} % clear all
    \fancyfoot[C]{\thepage\ of \pageref{appex}}%
    \renewcommand{\headrulewidth}{0pt}% no rule 
}

\fancypagestyle{xtra}{% for appendix
    \fancyhf{} % clear all
    \fancyfoot[C]{\thepage\ of \pageref{LastPage}}%
    \renewcommand{\headrulewidth}{0pt}% no rule 
}

\pagestyle{fancy}   

\usepackage[left=5.00cm, right=5.00cm, top=4.00cm, bottom=5.00cm]{geometry}

\usepackage[final]{pdfpages}

\title{A proposal}

\let\oldappendix\appendix %  added <<<<<<<<<<
\renewcommand{\appendix}{\label{appex}\clearpage\pagestyle{xtra}\pagenumbering{roman}\oldappendix} % added <<<<<<<<<<

\begin{document}    

    \maketitle
    
    \kant[1-12] % make six pages        
    
    \appendix % added <<<<<<<<
            
    \includepdf[pages=-,pagecommand={ }]{TermsConditions.pdf}       
    
\end{document}
Related Question