2

An issue with centering

I am trying to include several pages of a pdf within a document (hence using includepdf). These take up most of the page, so a 1-to-1 page input to page output is desired. The main document is two sided with odd and even margins set and some fancy headers. When I include the pdf pages, these are not respecting the page margins (seemingly always centred). How can I get the page margins to be preserved? (I would also like the solution to have the included pdfs vertically centred in the space the text would otherwise fill). I don't want to enforce that the included pages start after a \cleardoublepage, but just a \clearpage.

Undesired alignment from includepdf

Using the code (as in the MWE)

\includepdf[page={3-4}, frame, trim={30mm 50mm 30mm 50mm}, clip=true, pagecommand={\pagestyle{fancy}},width=\linewidth]{dummy_pages}

enter image description here

The sort of alignment I want from includegraphics

Instead using:

\noindent
\fbox{\includegraphics[width=\linewidth, page=3, trim={30mm 60mm 30mm 60mm}, clip=true]{dummy_pages}}

The alignment here is better albeit I think the inner margin is still not perfectly aligned despite stating width=\linewidth.

enter image description here

MWE

I have created a pdf file called dummy_pages.pdf which is dozens of page of lipsum.

\documentclass[a4paper,11pt,twoside]{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{pdfpages}
\usepackage[top=20mm,bottom=20mm,left=20mm, right=30mm, heightrounded, marginparwidth=24mm,  marginparsep=3mm, headsep=10mm]{geometry} 

% The nice headers and footers.
\pagestyle{fancy}
% Specifying the headers and footers. 
\fancyhf{}
\renewcommand*{\headrulewidth}{1pt}%
\fancyhead[LO]{\nouppercase{\leftmark}}
\fancyhead[RE]{\nouppercase{\rightmark}}
\fancyhead[LE,RO]{\thepage}
\fancypagestyle{plain}{%
    \fancyhf{}%
    \renewcommand*{\headrulewidth}{0pt}%
}
\cfoot{}

\begin{document}
\lipsum
\clearpage

\includepdf[page={3-4}, frame, trim={30mm 50mm 30mm 50mm}, clip=true, pagecommand={\pagestyle{fancy}},width=\linewidth]{dummy_pages}

\end{document}

Here the fancy headers shows the page numbering and margins.

Related material

There is a related question and answer here to how to position pdf with \includepdf in book, also depending on even/odd page. However, their "solution" is more of a one-off hack than a solution.

3

Isn't this what offset is for? It adapts automatically to even/odd pages, so you just need half the difference between the inner and outer margins.

\documentclass[a4paper,11pt,twoside]{book}
\usepackage{kantlipsum}
\usepackage{fancyhdr,calc}
\usepackage{pdfpages}
\usepackage[top=20mm,bottom=20mm,left=20mm, right=30mm, heightrounded, marginparwidth=24mm,  marginparsep=3mm, headsep=10mm]{geometry} 

% The nice headers and footers.
\pagestyle{fancy}
% Specifying the headers and footers. 
\fancyhf{}
\renewcommand*{\headrulewidth}{1pt}%
\fancyhead[LO]{\nouppercase{\leftmark}}
\fancyhead[RE]{\nouppercase{\rightmark}}
\fancyhead[LE,RO]{\thepage}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand*{\headrulewidth}{0pt}%
}
\cfoot{}
\begin{document}
\kant[1]
\clearpage

\includepdf[page={3-4}, frame, trim={30mm 50mm 30mm 50mm}, offset=-5mm 0, clip=true, pagecommand={\pagestyle{fancy}},width=\linewidth-2\fboxsep-2\fboxrule]{dummy}

\end{document}

offset pages

You can use the other offset value for vertical displacement, if you want that to be different.

| improve this answer | |

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.