latexpdflatex

Setting a newgeometry in latex with geometry package version 5 and higher


I am trying to set up a new page geometry with geometry package version 5.9. Earlier (Geometry package version 4.x) the code below would give the right result with a full-width head and foot rule. Now it only goes to 70% of the page. That's a feature according to the manual. So I have two problems.

  1. The head and foot rule doesn't go the full page width.
  2. The text goes below the page.

I understand it's a margin and layout problem, but I don't know how to fix it. Any help will be appreciated.

%!TeX program=pdflatex
\documentclass[12pt]{article}

\usepackage[a4paper]{geometry}
% \usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{lipsum}

% \graphicspath{{./figures/}}

\fancypagestyle{firstpageform}{%
    \renewcommand{\headrulewidth}{1pt}
    \renewcommand{\footrulewidth}{1pt}
    \newgeometry{%
        layout = a4paper,%
        top = 75pt,%
        hmargin=30pt,
        bottom = 75pt,%
        headsep = 50pt,%
    }% 
    % \lhead{\raisebox{8pt}{\includegraphics[width=0.15\linewidth]{institute_logo}}}
    \chead{\textbf{COMPANY NAME}\\
        Address Line 1, Post - YYYYYY,\\
        City - PIN, State, Country\\
        \texttt{www.company.website}, \texttt{email@id}\\
        Contact No: +YY-YYY-YYYY-YYY/ZZZ, +QQ-QQQ-QQQQ-QQQ}
    \lfoot{\today}
    \cfoot{}
    \rfoot{\thepage/\pageref{LastPage}}
}

% \fancypagestyle{form}{%
%    \newgeometry{%
%        layout = a4paper,%
%        top = 58pt,%
%        hmargin = 30pt,%
%        bottom = 55pt%
%    }
%    \renewcommand{\headrulewidth}{1pt}
%    \renewcommand{\footrulewidth}{1pt}  
%    \lfoot{\today}
%    \cfoot{}
%    \rfoot{\thepage/\pageref{LastPage}}
% }

\setlength{\parskip}{5pt}
\setlength{\parindent}{0pt}

% \pagestyle{form}

\begin{document}
\thispagestyle{firstpageform}

\lipsum[1-20]    

\end{document}

Solution

  • I finally got the answer from here. The trick is to use

    \fancyhfoffset[E,O]{0pt}
    

    after using \newgeometry{} command. The problem of vertical margin still exists to some extent, but not noticeable.