# How to add section number to PDF included with \includepdf?

I am inserting PDF documents into my document as an appendix. I am also using the addtotoc option to include a reference in my table of contents. Each PDF is then assigned a letter in the TOC from "A" onwards. I would like that letter to be printed in the top corner of the first page of the included PDF so someone flicking through can see where they are at in the Appendix. It would be good for it to say something like "Appendix A".

You can put section commands with the pagecommand option argument to \includepdf. No addtotoc is needed. This puts a section header at the top of each PDF and maintains continuous page numbering.

One drawback here is that you have to make sure that the included PDF has enough white space for the heading (you can scale the PDF in the \includepdf options) or you could put the heading on a separate page. You also have to specify the range of pages explicitly, but there may be a better way to do this.

For better control over section titles and format in the appendix, you might try the memoir class or the appendix package.

For this example, first compile the PDF to include (sans-serif font used to differentiate it from the main document):

\documentclass{article}
\usepackage{lipsum}
\renewcommand*\familydefault{\sfdefault}

\begin{document}

\pagestyle{empty}
\vspace*{2\baselineskip}
\lipsum[1-10]

\end{document}


Now include that PDF in this document (be sure to compile twice for the table of contents):

\documentclass{article}
\usepackage{pdfpages}
\usepackage{lipsum}

\begin{document}

\tableofcontents

\section{Main Text}
\lipsum[1-3]

\appendix

%PDF one
\includepdf[pages=1, pagecommand={\thispagestyle{plain}\section{Included PDF}}]{sample.pdf}
\includepdf[pages=2, pagecommand={\thispagestyle{plain}}]{sample.pdf}

%PDF two
\includepdf[pages=1, pagecommand={\thispagestyle{plain}\section{Another Included PDF}}]{sample.pdf}
\includepdf[pages=2, pagecommand={\thispagestyle{plain}}]{sample.pdf}

\end{document}