49

I have a chapter of attachments which contains pdf files in this format, using the awesome pdfpages package:

\chapter{Title}
Lots of multipage pdfs following
\includepdf[pages=-,frame,scale=0.9]{abc.pdf}
\includepdf[pages=-,frame,scale=0.9]{def.pdf}
...

This works, but apparently clears out the header and page numbers of the parent document. What setting do I have to change to get back the header and page numbers?

Hauke
  • 1,179
  • 2
  • 9
  • 8
  • 1
    As far as I understand ---and unfortunately--- this is not possible. However, I do have a little hope because the table of contents points to the correct page when using multiple \includepdf – Mario S. E. Jun 06 '13 at 16:41

2 Answers2

48

You can use the pagecommand key to declare the desired page style for the included pages:

\documentclass{book}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{fancyhdr}
\usepackage{pdfpages}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{Some centered header}
\fancyfoot[C]{\thepage}

\begin{document}

\includepdf[pages=-,pagecommand={\pagestyle{fancy}}]{b}

\end{document}

The file b.tex used to produce b.pdf is:

\documentclass{book}
\usepackage[a6paper]{geometry}
\usepackage{lipsum}
\pagestyle{empty}
\begin{document}
\lipsum[1-3]
\end{document}

The resulting document, after the inclusion is (notice that the included pages have the fancy page style of the parent document):

enter image description here

Gonzalo Medina
  • 505,128
  • 1
    Thanks! What is the reason for the missing header and page numbers? If I understand your post correctly, I am generating a 'new header'. Can I ask Latex somehow to use the parent document format 'original header' rather than the fancyhdr? – Hauke Jun 07 '13 at 07:39
  • what is the solution if scrpage2 is used instead of fancyhdr – Micha Jun 07 '13 at 07:46
  • 11
    I got it! \includepdf[pages=-,frame,scale=0.85,pagecommand={\pagestyle{plain}}]{b.pdf} enforces the original header with page numbers. Without the scaling, the pdfs would overlap with the header. pagecommand={\pagestyle... got me on the right track. – Hauke Jun 07 '13 at 07:49
  • 1
    @Gonzola, I suspect that pdfpages automatically sets the pagestyle to empty...? – Hauke Jun 07 '13 at 07:51
  • 1
    @Hauke yes; the default for pagecommand is \pagestyle{empty}. – Gonzalo Medina Jun 07 '13 at 12:43
  • 1
    That's not correct. It is working because the \pagestyle{fancy} command in the preamble. If you remove that line it does not work. You have to write \includepdf[pages=-,pagecommand={\thispagestyle{fancy}}]{b} – ernesto Jan 20 '17 at 15:45
17

I had a similar problem which was easily solved by using pagecommand but without any additional style or package. Just this way :

\chapter{Title}
Lots of multipage pdfs following
\includepdf[pages=-,frame,scale=0.9,pagecommand={}]{abc.pdf}
\includepdf[pages=-,frame,scale=0.9,pagecommand={}]{def.pdf}

to force latex to use the current page style