6

In my appendix, I want to add several PDF documents (questionnaires) which I used in a study. I managed to implement an appendix and include the PDF files (not hard to do), but now I have two issues I cannot solve:

  1. I would like to see that the first page of my PDF is placed directly below the title of my appendix A. Yet, appendix A is standing solo on the beginning of the page, then a lot of unused space followes, followed by the next page with the content of the PDF.
  2. At the moment, the PDF pages are covering the header of the sections (A Appendix). I would like to see the headers followed by the PDF pages ... Is this even possible?
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\newpage
\appendix
\section{Appendix A}

\includepdf[pages={1-2}]{Example.pdf}

\end{document}
  • The issue is that pdfpages by design imports the pages each on their own page. Is there a reason you can't build the whole document all together, instead of piecing them together afterwards? – cslstr May 9 '14 at 0:04
  • 1
  • 1
    tex.stackexchange.com/a/160677/39222 is my answer to a slightly different question but the problem is essentially similar. It demonstrates how to include a PDF page with the chapter header and headings appearing. (It involves multiple logical pages per physical page so it complicates but you could cut that stuff as you don't need it.) – cfr May 9 '14 at 0:38
  • 1
    @cfr It would not solve the first part of the question; a full page section heading would still be necessary. But \pdfpages could include the external PDF full page with headers. To include section headers, the external doc would have to be scaled down as you have shown. – cslstr May 10 '14 at 2:14
  • 1
    @cslstr Indeed. That's what my solution does except that I use a scaling factor. Of course, if the PDFs are such that there is already room for the headers, you can just set the scaling factor to 1 for that case to avoid unnecessary reductions in size. However, if they were produced in Word, they are likely to have smaller margins than the LaTeX document so I suspect some scaling may be necessary. If you are going to do this for a bunch of PDFs, though, it is useful to wrap the command in a macro for the sake of consistency and easy adjustment. – cfr May 10 '14 at 2:20
6

Here is an adapted version of the code given in the answer I linked to. You will need to adjust this depending on the class and packages you are using and on how full the pages of your PDFs are. The code below is conservative and assumes the pages are quite full though the sample PDF I included doesn't meet this requirement so the pages look too empty. I'm guessing your PDFs are fuller but obviously that's just a guess.

\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{pdfpages}
\usepackage{xparse}
\usepackage{kantlipsum}

\makeatletter
\NewDocumentCommand\headerspdf{ O {pages=-} m }{% [options for include pdf]{filename.pdf}
  \includepdf[%
    #1,
    pagecommand={\thispagestyle{fancy}},
    scale=.7,
    ]{#2}}
\NewDocumentCommand\secpdf{somO{1}m}{% [short title]{section title}[page specification]{filename.pdf} --- possibly starred
  \clearpage
  \thispagestyle{fancy}%
  \includepdf[%
    pages=#4,
    pagecommand={%
      \IfBooleanTF{#1}{%
        \section*{#3}}{%
        \IfNoValueTF{#2}{%
          \section{#3}}{%
          \section[#2]{#3}}}},
    scale=.65,
    ]%
    {#5}}
\makeatother

\pagestyle{fancy}

\begin{document}

\newpage
\appendix

\secpdf*{PDF on Starred Section Page}[3]{/usr/local/texlive/2013/texmf-dist/doc/latex/mwe/mwe.pdf}
  \kant[2]

\section{Include PDF after Section Page}
\kant[1]
\headerspdf[pages=1-2]{/usr/local/texlive/2013/texmf-dist/doc/latex/mwe/mwe.pdf}

\secpdf{PDF on Section Page}[4]{/usr/local/texlive/2013/texmf-dist/doc/latex/mwe/mwe.pdf}
\kant[2]

\secpdf[Short Title]{PDF on Section Page with Short Title}{/usr/local/texlive/2013/texmf-dist/doc/latex/mwe/mwe.pdf}
\kant[3]
\headerspdf[pages=2-3]{/usr/local/texlive/2013/texmf-dist/doc/latex/mwe/mwe.pdf}

\end{document}

Sample output:

PDF following section heading with headings

  • thanks for your help. the preamble + the code \secpdf[Short Title]{PDF on Section Page with Short Title}{Example.pdf} works very well so far, the whole page is shown perfectly on the page... only problem: if I add a pdf with more than one page, it only displays first page, rest is not shown up. how can I solve this issue? – Jens May 9 '14 at 19:01
  • Sorry, had a logical failure here :) Of course \secpdf[Short Title]{PDF on Section Page with Short Title}{Example.pdf} is used for the first page, then I add \headerspdf[pages=2-X]{Example.pdf} for all remaining pages! Thanks a lot :) – Jens May 9 '14 at 19:27
  • 1
    @Jens Yes. The question I linked to has more explanation but it is for chapters rather than sections and has some other complications. Probably you want the scaling factor to be a little different on pages with a section title so it is easiest to have two commands so that you can adjust the options separately for pages following a section heading and for pages with just headers. – cfr May 10 '14 at 2:07
  • A while later, I am using KOMA-script and get an error about using fancy-package here. Any suggestion for this? – Jens Jan 2 at 14:54
  • @Jens This answer does also work without fancyhdr. Just remove every \thispagestyle{fancy} and replace \pagestyle{fancy}, e.g., by \pagestyle{headings}. – Schweinebacke Jan 23 at 9:44
2

Alternatively, I add the PDF as follows:

\usepackage{pdfpages}
\includepdf[pages=-,offset=75 -75]{myfile.pdf}
  • 1
    Set offset=0 0 instead if using whole-page PDF's. – Ludwik Oct 17 '18 at 17:15
1

Just in case someone else stumbles on this looking for an answer. I found that you could just use the \section{appendix} command as part of the pagecommand:

\begin{appendix}
  \centering
  \includepdf[pages=2,scale=0.9,offset=0mm -75,pagecommand={
  \begin{flushleft}  
    \section{Appendix}
  \end{flushleft}
   \section{AnyPdf}\label{AnyPdf}}linktodoc=false]{AnyPdf.pdf}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.