[Tex/LaTex] using LaTeX pdfpages and geometry packages together

pdfpages

I would like to embed a pdf document (few pages) in my latex document. However, I use the geometry package to set the margins and when I load \usepackage{pdfpages} it completely destroys all my margins.

I have:

\usepackage[a4paper, twoside, scale={1,1},
            hmargin={3.3cm, 2.7cm},
            vmargin={2cm, 4.5cm},
            headsep=0.5cm]{geometry}

when I use \usepackage{pdfpages} then it changes all my margin and my document looks like the attached image enter image description here. Basically using the pdfpages shifts my texts to header section.

I would appreciate if someone tells me how to resolve this issue.

here is a MWE (minimum working example). It does not show the exact error but you see if you comment line 83 (\usepackage{pdfpages}) the margins are different. Note that I do not even use \includepdf yet.

\documentclass[11pt,a4paper,twoside]{report} %physics

\usepackage[dvips]{graphicx}
\usepackage{setspace}
\usepackage{fancyhdr, lastpage}
\pagestyle{fancy}
\usepackage{nomencl}
\usepackage{colortbl}
\usepackage{multirow}
\usepackage{parskip}
\usepackage{hyperref}
\usepackage{titlesec}
\usepackage{xcolor,colortbl}
\usepackage{blindtext}

\definecolor{darkblue}{rgb}{0.0,0.0,0.0}  %{0.0,0.0,0.3}
\hypersetup{colorlinks,breaklinks,
            linkcolor=darkblue,urlcolor=darkblue,
            anchorcolor=darkblue,citecolor=darkblue,
            pdftitle = {Test Procedure: Tank Testing},
            pdfauthor = {Ashkan}}
\renewcommand{\nomentryend}{\vspace{-8pt}}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

%%%To be able to have smaller fonts
\newcommand{\changefont}{%
    \fontsize{8}{11}\selectfont
}

%%%To be able to have larger fonts
\newcommand{\changefonttitle}{%
    \fontsize{12}{11}\selectfont
}
%%%%%%%%%%%%%%%%%%
\titleformat{\chapter}
  {\normalfont\LARGE\bfseries}{\thechapter.}{0.5em}{}
\titlespacing*{\chapter}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%Creating a new colour Light Blue for the table on the front page
\definecolor{LightBlue}{rgb}{0.3,0.6,1.0}

%%%To have headers/footers on the title page
\fancypagestyle{empty}{%
 \renewcommand{\headrulewidth}{0.4pt}%
  \fancyheadoffset{0.0cm}
  \fancyfootoffset{0.0cm}
  \renewcommand{\footrulewidth}{0.4pt}
  \fancyhf{}%
  \fancyhead[L]{\changefont {\textsc{TEST PROCEDURE -- TANK TESTING}}}
  \fancyhead[R]{\includegraphics[scale=0.3]{./logo.png}}
  \fancyfoot[C]{\changefont{\color{red}{CONFIDENTIAL -- COMERCIAL IN CONFIDENCE \\ THIS DOCUMENT IS UNCONTROLLED WHEN PRINTED}} }%  
}


%%%To have headers/footers on the pages that are using plain template
\fancypagestyle{plain}{%
 \renewcommand{\headrulewidth}{0.4pt}%
  \fancyheadoffset{0.0cm}
  \fancyfootoffset{0.0cm}
  \renewcommand{\footrulewidth}{0.4pt}
  \fancyhf{}%
  \fancyhead[L]{\changefont {\textsc{TEST PROCEDURE -- TANK TESTING}}}
  \fancyhead[R]{\includegraphics[scale=0.3]{./logo.png}}
  \fancyfoot[C]{\changefont{\color{red}{CONFIDENTIAL -- COMERCIAL IN CONFIDENCE \\ THIS DOCUMENT IS UNCONTROLLED WHEN PRINTED}}\\}%  
  \fancyfoot[RE, RO]{Page {\thepage} of \pageref{LastPage}}  
}

\makeglossary
%%%%%%%%%%%%% Mike's section %%%%%%%%%%%%%%%%%%%%%%%
\usepackage[a4paper, twoside, scale={1,1},
            hmargin={3.3cm, 2.7cm},
            vmargin={2cm, 4.5cm},
            headsep=0.5cm]{geometry}

\onehalfspacing
\usepackage{pdfpages}
%%%%%%%%%%%%% end of mike's section %%%%%%%%%%%%%%%%

\begin{document}

\title{
\textsc{\\*[-2cm] Test Procedure \\ Tank Testing}
}
\author{}

\date{\raggedright}

\maketitle
\thispagestyle{empty}%
\pagenumbering{roman}%
\setcounter{secnumdepth}{-1}%
\thispagestyle{empty}%
\tableofcontents

\clearpage%
%--------------------------------------------------------------------------
\pagenumbering{arabic} \setcounter{secnumdepth}{3}

\pagestyle{fancy}%
  \fancyheadoffset{0.0cm}
  \fancyfootoffset{0.0cm}
  \renewcommand{\headrulewidth}{0.4pt}%
  \renewcommand{\footrulewidth}{0.4pt}
  \fancyhf{}%
  \fancyhead[L]{\changefont {\textsc{Specification -- Tank Testing Model}}
  \fancyhead[R]{\includegraphics[scale=0.3]{./logo.png}}
  \fancyfoot[C]{\changefont{\color{red}{CONFIDENTIAL -- COMERCIAL IN CONFIDENCE \\ THIS DOCUMENT IS UNCONTROLLED WHEN PRINTED}}\\}%  
  \fancyfoot[RE, RO]{Page {\thepage} of \pageref{LastPage}}


%%%%%%%%%%%%Chapters (Contents of the document)%%%%%%%

%------------------------------------------------------------------------------------------
\blindtext[10][10]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}

to run you need this enter image description here save it in the same folder as logo.png.

Best Answer

The image logo.png is much too large for the header, from the .log file:

Package Fancyhdr Warning: \headheight is too small (12.0pt): 
 Make it at least 56.17505pt.
 We now make it that large for the rest of the document.
 This may cause the page layout to be inconsistent, however.

Also package geometry throws a warnings:

Package geometry Warning: Over-specification in `h'-direction.
    `width' (597.50787pt) is ignored.

Package geometry Warning: Over-specification in `v'-direction.
    `height' (845.04684pt) is ignored.

Removing option scale and adding headheight fixes these issues:

\usepackage[a4paper, twoside,
            hmargin={3.3cm, 2.7cm},
            vmargin={2cm, 4.5cm},
            headheight=56.17505pt,
            headsep=0.5cm]{geometry}  

The warning

pdfTeX warning (ext4): destination with the same identifier
(name{page.1}) has been already used, duplicate ignored

can be avoided by disabling page anchors for the title page:

\begin{document}
\hypersetup{pageanchor=false}
...
\maketitle
\hypersetup{pageanchor=true}
Related Question