4

I am using the pdfpages package a lot for including either single pages or multiple pages in my document (measurement diagrams, several pages of external documentation, ...). I do not want to include those as pictures by \includegraphics{}, since that would resize them too much. The included pages usually have a format of being printed already anyway.

\documentclass{scrartcl}

\usepackage{pdfpages}

\begin{document}
% Include a single PDF page
\includepdf[
    frame,
    scale=0.90
]{pdfdocument.pdf}

% Include a pdf-document with several pages
\includepdf[
    pages=-,                
    nup=1x2,                
    frame,                  
    landscape,          
    delta=5mm 5mm,  
    scale=0.95,         
]{pdfdocument.pdf}

\end{document}

Any idea on how to set a description, caption or similar below or above the included document?

See this sketch for explanation.

enter image description here enter image description here enter image description here

  • You can use pagecommand and insert header or footer for each page. If for one page use thispagestyle macro. Do it for each pdf assuming that they are all one page documents. – user11232 Apr 7 '14 at 11:38
  • Hello Harish, this was my first guess. Did not work for me well, so far, since the page layout needs to be changed constantly. I was already stopped by changing the layout accordingly with scrlayer-scrpage. – Benjamin Apr 7 '14 at 12:15
  • Welcome to TeX.SX! The question is of high quality. You can have a look at our starter guide to familiarize yourself further with our format. – strpeter Apr 7 '14 at 12:16
5

This answer attempts to do what you are asking via these steps:

  1. Use geometry to set margins to accommodate the captions and page numbers you want.
  2. Use caption package for its \captionof and \captionof* commands to set the captions.
  3. Use pdflscape and wrap landscape pages in landscape environment to set captions in the proper orientation.
  4. The example assumes one caption per included document. To do this, pdfpages is patched to offer a pagecommand* option that will allow for a different command to be executed on the first page of included pages. The way I have written things, pagecommand* is executed on the first page, and pagecommand is executed on second and subsequent pages (though this could be changed relatively easily if desired). If you desire a different caption for different pages, it will be best to include the document 2 pages at a time (and in this case, the patches are not necessary).

Example Output:

The output that is given provides the page number on all pages (in portrait layout, ideal for printing).

page1

page2

page3

The Code

This code has been commented to give an idea of what was changed where.

\documentclass{scrartcl}

\usepackage{caption}  % Use for \captionof(*) command

% Set the page margins to accomodate space for captions and page numbers
\usepackage[left=0.9cm,right=0.9cm,bottom=1cm,footskip=1em,includefoot]{geometry}
% Use for 'landscape' environment to position landscape captions properly
\usepackage{pdflscape}

% Setup the new 'pagecommand*' option key-value
\usepackage{etoolbox}
\usepackage{pdfpages}
\makeatletter
\newcommand*{\AM@pagecommandstar}{}
\define@key{pdfpages}{pagecommand*}{\def\AM@pagecommandstar{#1}}
\patchcmd{\AM@output}{\begingroup\AM@pagecommand\endgroup}
{\ifthenelse{\boolean{AM@firstpage}}{\begingroup\AM@pagecommandstar\endgroup}{\begingroup\AM@pagecommand\endgroup}}{}{} % Patch to use new option
\patchcmd{\AM@split@optionsii}{\equal{pagecommand}{\AM@temp}\or}
{\equal{pagecommand}{\AM@temp}\or\equal{pagecommand*}{\AM@temp}\or}{}{}
\makeatother

\begin{document}

% Include a single PDF page
\includepdf[
    frame,
    scale=0.90,
    % Use new 'pagecommand*' to set caption on the first page, include page #
   pagecommand*={\thispagestyle{plain}\null\vfill\captionof{figure}{This is the FIRST caption}}
]{pdfdocument.pdf}

% Include a pdf-document with several pages
\begin{landscape} % Be sure to wrap in 'landscape' environment
\includepdf[
    pages=-,                
    nup=1x2,                
    frame,                  
    landscape,          
    delta=5mm 5mm,  
    scale=0.90,
    % Set the caption on the first page of output
    pagecommand*={\thispagestyle{plain}\null\vfill\captionof{figure}{This is the SECOND caption}},
    % Set the [continued] caption on second and subsequent pages
    % Use '\captionof*{...} to avoid duplicate entries in listoffigures
    pagecommand={\thispagestyle{plain}\null\vfill\captionof*{figure}{\figurename~\thefigure: This is the SECOND caption (Continued)}}
]{pdfdocument.pdf}
\end{landscape}

\end{document}
  • This was very helpful for adapting to another style! – Benjamin Apr 8 '14 at 12:49
0

Another solution using the \addtolist functionality of pdfpages, and changing the layout with geometry.

\documentclass{scrartcl}

\usepackage{pdfpages}
\usepackage{lipsum}

\usepackage{geometry}
\geometry{a4paper}

\usepackage[]{scrlayer-scrpage}

% Fußzeile
\ofoot[\pagemark]{\pagemark}
\cfoot[]{Section}
\ifoot[]{Document number}
\pagestyle{scrheadings}

\newcommand{\pdfportrait}[2]{
\newgeometry{bottom=0.5cm,includefoot}
\cfoot[#1]{}
\includepdf[
    frame,
    scale=0.90,
    addtolist={1,figure,#1,#1},
    pagecommand={\thispagestyle{plain}}
]{#2}
\restoregeometry
}

\newcommand{\pdfbooklet}[2]{
\newgeometry{bottom=0.5cm,includefoot}
\cfoot[#1]{}
\includepdf[
    pages=-,                
    nup=1x2,                
    frame,                  
    landscape,          
    delta=5mm 5mm,  
    scale=0.90,
    addtolist={1,figure,#1,#1},
    pagecommand={\thispagestyle{plain}}
]{#2}
\restoregeometry
}

\begin{document}

\listoffigures

\lipsum

% Include a single PDF page
\pdfportrait{Single page portrait oriented}{pdfdocument.pdf}

\lipsum

% Include a pdf-document with several pages
\pdfbooklet{Multiple pages - 2 per page}{pdfdocument.pdf}

\lipsum

\end{document}

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

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.