[Tex/LaTex] Setting up pdfpages with memoir

memoirpdfpages

I am using memoir for writing my PhD thesis. In my university we have to include submitted, accepted, and prepared drafts of related papers as appendices.

These papers have all been previously created using LaTeX (using the class elsarticle). I have them as PDF with white borders/margins stripped away using Adobe Acrobat. They are therefore in different sizes.

My question is in regard to pdfpages. How can I make sure that a pdf-page is inserted correctly on a full document-page (without a Chapter-title).

I use the following class-options and predefined layout:

\documentclass[a4paper,12pt,twoside,onecolumn,openright,final,showtrims]{memoir}
\semiisopage[12]
\checkandfixthelayout

My problem is that pdfpages seems to center the pdf-page itself on the entire stock (if we use memoir-jargon). I want the pages to center/fit in the area delimited by lengths such as \textwidth and \textheight (defined in the memoir manual, memman.pdf, on page 10 and 11).

I use the following options with \includepdf:

\includepdf[
    pages={-},
    frame=false, % so I can adjust this if I need it
    noautoscale=true, % I should scale it myself, right?
    scale=1.0, % is this 1.0 by default?
    pagecommand={\thispagestyle{plain}}, % I guess this is necessary?
    %templatesize={\textwidth}{\textheight}, % not sure this work?
    offset={0mm 0mm} % my guess is, that I need to adjust this one?
]{<paper_pdf_filename>}

As I mention above, I would likely need to adjust offset so that the pages are placed/fitted in the area called "body" on page 10-11 in the memoir manual.

Further elaborations:

I would like the pages of each paper to be part of the surrounding document. The entire thesis will still have material after the inserted papers. It will continue with a global reference section and perhaps even a short index. The inserted pages of each paper should exist as if they are exactly that – inserts – not pages on their own. Which is why I use the pagestyle plain to include the thesis page number.

If you take a look at memman.pdf on page 10-11, you will see the different page-margins for the memoir-class. I need the logic box of each inserted page to have an offset such that is correct in regards to these margins.

I have tried the following (using the calc-package):

\newcommand{\pdfxoffset}{\marginparsep + \marginparwidth + \trimedge}
\newcommand{\pdfyoffset}{\uppermargin + \trimtop}

With these options for \includepdf:

pagecommand={\thispagestyle{plain}},
width=\textwidth,
height=\textheight,
offset={\pdfxoffset mm \pdfyoffset mm}

But it does not fit entirely as I want it (but almost). I am also not exactly sure what I am doing here. Can I just add lengths together like this? Not sure I even grasp the programming-language constructs in TeX/LaTeX.

Best Answer

I don't know memoir jargon, but if I understood you correctly, you want to insert a PDF that stretches to the normal \textwidth on an otherwise empty page. This can be achieved by defining a customized page style (unless redefined, plain would include a page number) and using the \includegraphics options width and height, which are passed on by pdfpages.

As pointed out by @egreg, with memoir and no pagestyle customizations needed, rather \thispagestyle{empty} should be used. Further, graphicx provides a parameter keepaspectratio which ensures that if both width and height of the PDF are specified, it is scaled such that the aspect ratio is kept and neither width nor height are exceeded.

\documentclass{article}
\usepackage{pdfpages}
\usepackage{fancyhdr}

\fancypagestyle{mystyle}{%
    \fancyhf{}%                             %clear headers, footers
    \renewcommand{\headrulewidth}{0pt}%     %and remove header rule
}

\begin{document}


\includepdf[pages=1,
            pagecommand={\thispagestyle{empty}}, %is default, only mentioned to show alternative usage of customized mystyle
            width=\textwidth,
            height=\textheight,     
            keepaspectratio,
            frame]{yourfile.pdf}            
\end{document}