# pdfpages not rendering multipage pdfs properly within figure in appendix

I'm trying to insert multipage pdf files in the appendix, using the pdfpages package. I am using [Overleaf][1].

This is the code I'm using after trying a few things:

\begin{appendices}

\chapter{Emails}

\newpage
\begin{figure}[ht]
\centering
\includepdf[pages=-]{emails/email1.pdf}
\caption{Email 1}
\label{Email1}
\end{figure}

...
\end{appedices}


The problem is that the pages are not laid out each on their own page, but are all written one over the other on one page, like this (these are actually 3 pages):

How can I fix this? I am open to other solutions to achieve this as well.

Thanks.

• don't use figure environment. – touhami Jan 4 '16 at 17:25

Here is a solution.

Package caption allow use of caption outside float environment.

The key point is pagecommand from pdfpages, one can use it to add stuff to included pages

\documentclass{book}
\usepackage{caption}
\usepackage{pdfpages}
\newcounter{mtpage}
\begin{document}
bla bla
\includepdf[pages=-,pagecommand={\stepcounter{mtpage}\null\vfill\captionof{figure}{Email 1 - page \themtpage }\label{Email1P\themtpage}}]{myfile.pdf}

\end{document}

• I tried this but it can't see \themtpage. Where is that coming from? – Vlad Schnakovszki Jan 9 '16 at 13:55
• this is a new counter for included pages – touhami Jan 14 '16 at 16:38

I ended up using a workaround. As detailed in this answer, pdfpages uses a separate page to render everything on, which doesn't work with multiple full sized pages.

Now if you don't need to reference or caption it, the solution is simple. Don't use the figure environment. Your code would be as simple as:

\begin{appendices}

\includepdf[pages=-]{emails/email1.pdf}

\end{appedices}


However, I need to both caption and reference so I have created a different workaround. It avoids using the pdfpages package and uses the graphicx package instead. I am using multiple figures, each containing a separate page of the document, like so:

\begin{appendices}

\chapter{Emails}
\newpage

\begin{figure}
\centering
\includegraphics[page=1,width=\textwidth]{emails/email1.pdf}
\caption{Email 1 - page 1}
\label{Email1P1}
\end{figure}

\begin{figure}
\centering
\includegraphics[page=2,width=\textwidth]{emails/email1.pdf}
\caption{Email 1 - page 2}
\label{Email1P2}
\end{figure}

\end{appendices}


If there's a simpler way to achieve what I need while preserving captions and references, please share it with us.