# Custom page numbers fail on last page of included chapters

TL;DR when I include an appendix into my master report, the custom page numbering fails on the last page of each appendix. How can I fix it?

I am creating a long report with appendices. I want roman page numbering for my preamble, arabic for the main body, and custom page numbers in the appendices, in the form A1, A2,.... It is all working fine, except that the last page of each appendix is reverting to standard arabic numerals, e.g. 3 rather than A3. The problem appears to be linked to the fact that I am including these appendices from separate files.

In the following MWE, the two appendices in the main file are numbered correctly, but the included file is not:

Main file

\documentclass{report}

\usepackage{standalone}         % Allow included files to also be compiled standalone
\usepackage{etoolbox}

\usepackage{lipsum}             % For testing

\begin{document}
\pagenumbering{roman}
\pagestyle{plain}

\tableofcontents

\clearpage
\pagenumbering{arabic}

\lipsum

\appendix
\pretocmd{\chapter}{%
\clearpage
\pagenumbering{arabic}%
\renewcommand*{\thepage}{\thechapter\arabic{page}}%
}{}{}

\chapter{First appendix}
\lipsum

\include{include}

\chapter{Third appendix}
\lipsum
\end{document}


include.tex

\documentclass{report}
\begin{document}
\chapter{Included appendix}
\lipsum
\end{document}


I have tried the solution to Pagestyle plain. No page number on last page of chapter. It just gave me undefined control sequence errors.

How can I ensure that the page number on the last page of the included file gets the same formatting as the other appendix pages?

standalone adds additional grouping and so your redefinition of \thepage gets lost. Move it directly behind \appendix and reset the page number with setcounter instead of pagenumbering:

\documentclass{report}

\usepackage{standalone}         % Allow included files to also be compiled standalone
\usepackage{etoolbox}

\usepackage{lipsum}             % For testing

\begin{document}
\pagenumbering{roman}
\pagestyle{plain}

\tableofcontents

\clearpage
\pagenumbering{arabic}

\lipsum

\appendix
\renewcommand*{\thepage}{\thechapter\arabic{page}}%
\pretocmd{\chapter}{%
\clearpage
\setcounter{page}{1}%
}{}{}

\chapter{First appendix}
\lipsum

\include{include}

\chapter{Third appendix}
\lipsum
\end{document}