# Setting up pdfpages with memoir?

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.

• The fact that pdfpages is not affected by the text area is one of its main features IMHO. You can use \includegraphics[page=..,width=\textwidth,height=\textheight,keepaspectratio]{..} instead for every page. I recently finished my PhD thesis and I did not use the same text area for the papers in the appendix. – Martin Scharrer Jun 14 '12 at 8:42
• Thanks. It seems to help if I use \textwidthand \textheight. If the attempts with the margins fail completely I will use this as a method to fall back to. – Ole Thomsen Buus Jun 14 '12 at 11:59
• @OleThomsenBuus I think I've figured out most of the offset you need, but a slight difference remains -- maybe someone else can answer this new question: proper alignment of pdfpages import in memoir typeblock – dgs Jun 14 '12 at 19:31
• @dgs Thanks for the effort though. It seems you have not gotten much feedback on it. The single vote up was from me btw. I can't comment on your question ... and currently I have no answer :) I think I have accepted that each pdf-page gets centered in a page. But this latex-fiddling also a form of procrastination really. Should just write instead. – Ole Thomsen Buus Jun 17 '12 at 15:31
• Sure, fiddling can be great fun. Concerning the question, I wouldn't preclude the problem's a bug, so there might not even be an answer (thanks for the vote, btw.). However, I'd consider your specific problem as being virtually solved---did you try to add the difference in \spinemargin, as described in the other question? The figure there is at 800% magnification, so you might not even notice the remaining gap. Otherwise, just add some manually determined 1.x pt. Or is there anything else you need? – dgs Jun 17 '12 at 15:58

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}{%
}

\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}

• Thank you. I added some more necessary information in my question above. Not exactly what I needed, but now I know how to create pagestyles ... that's never useless :) – Ole Thomsen Buus Jun 14 '12 at 11:47
• Why not simply \thispagestyle{empty}? Using fancyhdr with memoir is not really recommended. Also the options width=\textwidth,height=\textheight,keepaspectratio will make the included PDF not exceed any of the dimension, while not distorting the image. – egreg Jun 14 '12 at 12:06
• @egreg En bref: Not thought of/not known the parameter. Thanks. – dgs Jun 14 '12 at 12:25
• I believe that pdfpages use \thispagestyle{empty} in pagestyle by default? – Ole Thomsen Buus Jun 14 '12 at 12:29
• True. I'd nevertheless consider it useful to leave in the customized style definition as an alternative. I'll add a comment. – dgs Jun 14 '12 at 12:38

Another answer*: According to my assumption stated in proper alignment of pdfpages import in memoir typeblock, for twoside layout the difference in \spinemargin between oneside and twoside needs to be chosen as the horizontal offset. To find the values of \spinemargin, uncomment the \the commands (which print the current parameter values) and compile once with oneside option and again with twoside selected. Note the values and compute the difference. There might be a way to automate this if switching the layout options within the document is feasible; I used a calculator. For reasons yet unknown (cf. the linked question), the computed value needs to be slightly adjusted; I've subtracted 1pt.

If you want the PDF to be vertically centered within the typeblock, set the vertical offset to zero. Should it be aligned to the top or bottom, the difference between the type area height and the height of the scaled imported PDF needs to be computed. If the imported PDF is an A4 format, the height-to-width ratio is the square root of two. Since the PDF is scaled such that its width equals \textwidth, multiplication of \textwidth with sqrt(2) yields the scaled height of the imported PDF. The height of the type area is given by \textheight. The required offset then is half of the difference of the two heights, either positive or negative for top or bottom alignment. Again, this value needs to be slightly adjusted; I've subtracted 1.68pt.

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

\usepackage{pdfpages}
\usepackage{showframe}  %show page geometry

\begin{document}

%   \the\spinemargin \quad      %compute xoffset = \spinemargin(twoside) - \spinemargine(oneside) = -21pt
%   \the\textheight         %compute yoffset = .5 (\textheight - scaled-a4paper-height) = 25.18pt, with scaled-a4paper-height = \textwidth * (height(a4paper) / width(a4paper)) = \textwidth * sqrt(2)

\includepdf[pages=1-2,
pagecommand={\thispagestyle{plain}},
width=\textwidth,
height=\textheight,
keepaspectratio,
offset=-22pt 23.5pt %for vertically centered alignment, set yoffset=0pt
]{a4red.pdf}
\end{document}


*While my first answer is concerned with the import parameters, this one is about finding the right offset values. One could argue that the question should have been split; anyway, it doesn't seem to make sence to merge the answers.