1

I want to generate a document which has a header and footer on the first page but only a footer on all other pages. I used fancyhdr for the header, I have a general header style and one for the first page which uses \thispagestyle. This works fine.

My problem is that the page does not change its geometry. The \textheight keeps its old height, how do I change it?

I wrote a little example:

\documentclass[a4paper]{article}

% packages
\usepackage[includeheadfoot, heightrounded, left=2cm, right=2cm, top=5mm, bottom=1cm, headheight=5.5cm]{geometry}
\usepackage{everypage}
\usepackage{fancyhdr}

% only to show header and footer
\renewcommand{\headrulewidth}{0.1px}
\renewcommand{\footrulewidth}{0.1px}

% header and footer for first page
\fancypagestyle{firstpage}{
    \fancyhead[L]{%
        Header \\ for \\ the \\ first \\ page \\ wTestch \\ is \\ really \\ big
    }
    \fancyfoot[C]{Footer}
}
% all other pages
\fancypagestyle{normal}{
    \fancyfoot[C]{Footer Only}
}
\pagestyle{normal}

% try to change the style for all pages that have a smaller header
\AddEverypageHook{
    \ifnum\value{page}=1%
    \else
        % removes the header space but pushes everytTestng upwards
        \newgeometry{includeheadfoot, heightrounded, left=2cm, right=2cm, top=5mm, bottom=1cm, headheight=.5cm, footskip=-5.5cm}%
        \enlargethispage*{5cm} % does not work
        \setlength{\textheight}{\dimexpr(\textheight+5cm)} % does not work
        \addtolength{\textheight}{5cm} % does not work
    \fi
}

\begin{document}
    \thispagestyle{firstpage}
    Test
    \newpage
    Test

    ...
\end{document}

The in the resulting document (on page 2) you can see that the textheight is not increasing:Result of the example code, page 2 shows that the textheight is not big enough.

Site note: The LaTeX code is generated via a program so I do not know where the new page is inserted, neigther where the first page ends nor where other page breaks are. Also I cannot control the page breaks because the contents of the document is changing dynamically.

I hope somebody can help me with this problem.

1

Setup the normal page layout and use \vspace* on the first page to move the text down. To avoid that fancyhdr enlarges the header you must hide the height of the large header:

\documentclass[a4paper]{article}

% packages
\usepackage[includeheadfoot, heightrounded, left=2cm, right=2cm, top=5mm, bottom=1cm, headheight=.5cm]{geometry}
\usepackage{everypage}
\usepackage{fancyhdr}

% only to show header and footer
\renewcommand{\headrulewidth}{0.1px}
\renewcommand{\footrulewidth}{0.1px}

% header and footer for first page
\fancypagestyle{firstpage}{
    \fancyhead[L]{% hide height of header
        \raisebox{0pt}[0pt][0pt]{\begin{tabular}[t]{l}Header \\ for \\ the \\ first \\ page \\ wTestch \\ is \\ really \\ big\end{tabular}}
    }
    \fancyfoot[C]{Footer}
}
% all other pages
\fancypagestyle{normal}{
    \fancyfoot[C]{Footer Only}
}
\pagestyle{normal}

\usepackage{lipsum}
\begin{document}
    \thispagestyle{firstpage}\vspace*{5cm}
    \lipsum \lipsum
    %\newpage
    Test

    ...
\end{document}

enter image description here

  • Thank you for your answer. Your suggestion works and I will use it (and check it as the correct answer) if there is no better solution. You cannot know that but the problem for me is that it is not too simple to implement the changings in the header and document contents caused by the way the code is generated. – miile7 Mar 15 '18 at 13:43

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.