# Change \headheight for a \pagestyle

I have a document class that auto generates header from some user input. The problem is the first page should have a different page header than the others and the headline can be multi line. So \headheight is too small. Here is a demonstration of the problem:

\documentclass[twoside]{scrartcl}
\newcommand{\longfirstpagehead}{%
\begin{minipage}{10cm}
some\\long\\text\\text\\text\\text\\text\\text
\end{minipage}}
\newcommand{\normalhead}{normal}
\usepackage{scrpage2}

\newpagestyle{firstpage}{%
{\longfirstpagehead\hfill} %twoside links
{\longfirstpagehead\hfill} %twoside rechts
{\longfirstpagehead\hfill} %oneside
(\textwidth,1pt)
}{%
{\pagemark\hfill} %twoside links
{\hfill\pagemark} %twoside rechts
{\hfill\pagemark} %oneside
} %

\newpagestyle{normal}{%
{\normalhead\hfill} %twoside links
{\normalhead\hfill} %twoside rechts
{\normalhead\hfill} %oneside
(\textwidth,1pt)
}{%
{\pagemark\hfill} %twoside links
{\hfill\pagemark} %twoside rechts
{\hfill\pagemark} %oneside
} %

\pagestyle{normal}
\AtBeginDocument{
\thispagestyle{firstpage}}

\usepackage{blindtext}
\begin{document}
%\vspace*{1cm}
\blindtext

\blindtext
\pagebreak
\end{document}


I tried to read the height with \settototalheight and:

• add a \vspace at beginning of document (unnice hack):
• still the bad box warning (of cause)
• first section has different alignment
• manually change \headheight in pagestyle
• text height and page foot is wrong (can't change this because some scoping?)
• use Komascript in pagestyle
• \recalctypearea warning
• geometry in pagestyle
• pretty much the same problem like the manual attemp

So I would like to change the \headheight for the pagestyle firstpage, but the page should still have the same page margins, etc. The problem is that this has to work with \thispagestyle. (Better Ideas are also welcome) Something like \thispagegeometry in geometry would be great. ;)

-
In what sense the first section has a different alignment with an initial \vspace? –  egreg Feb 1 '12 at 22:17
Latex normally trys to fill the page, but the first section is still at top. With the vspace this behavior changed. Hmm, can't reproduce this problem in MWE. Maybe this page filling is non default –  someonr Feb 1 '12 at 22:25
What \vspace did you use? –  egreg Feb 1 '12 at 22:30
\vspace*. Sry, I think the MWE isn't including this problem. As soon as I find out why my cls is filling the page by increasing spaces, i'll add MWE. –  someonr Feb 1 '12 at 22:37
What argument to \vspace*? –  egreg Feb 1 '12 at 22:37
show 1 more comment

## 3 Answers

You can use the afterpage package to change the headheight. I hard coded the 3 cm headheight, but if you save the header text in a box, you can get its actual height.

\documentclass[twoside]{scrartcl}
\newcommand{\longfirstpagehead}{%
\begin{minipage}{10cm}
some\\long\\text\\text\\text\\text\\text\\text
\end{minipage}}
\newcommand{\normalhead}{normal}
\usepackage{scrpage2}
\newpagestyle{firstpage}{%
{\longfirstpagehead\hfill} %twoside links
{\longfirstpagehead\hfill} %twoside rechts
{\longfirstpagehead\hfill} %oneside
(\textwidth,1pt)
}{%
{\pagemark\hfill} %twoside links
{\hfill\pagemark} %twoside rechts
{\hfill\pagemark} %oneside
} %

\newpagestyle{normal}{%
{\normalhead\hfill} %twoside links
{\normalhead\hfill} %twoside rechts
{\normalhead\hfill} %oneside
(\textwidth,1pt)
}{%
{\pagemark\hfill} %twoside links
{\hfill\pagemark} %twoside rechts
{\hfill\pagemark} %oneside
} %

\usepackage{afterpage}
\pagestyle{normal}
\addtolength{\textheight}{-3cm}%
\addtolength{\headheight}{3cm}%
\AtBeginDocument{%
\thispagestyle{firstpage}%
\addtolength{\textheight}{3cm}%
\afterpage{%
\global\advance\headheight by -3cm%
}%
}

\usepackage{lipsum}
\begin{document}
\lipsum[1-30]
\end{document}


I had to use \global\advance\headheight by -3cm inside the afterpage. It seems like it should be possible to use \addtolength, but I couldn't get it to work.

-
Nice package. I'm using it now and it is working perfect. thx for help. –  someonr Feb 2 '12 at 23:58
add comment

Changing page geometry mid document is always a bit delicate. Easier and perhaps aplicable here is to put the head into a box witn a fixed, one line, height/depth, ovehanging its stated size. then just start your first page witha vspace* big enough to leave room.

-
yeah this would work. But a vspace at beginning make problems if latex tries to fill the page (as described in the question). How can I avoid this problem? Anyway I'm hoping for a better solution. –  someonr Feb 1 '12 at 22:09
I didn't understand the comment about vspace causing problems (or why you should get an overfull box warning for an intended overflow), I'll try your example see if that makes it clearer. (I was on android before don't have TeX there (yet?) –  David Carlisle Feb 1 '12 at 22:29
Sry, I'll edit the question. I think the MWE isn't reflecting this problem. I'll test. –  someonr Feb 1 '12 at 22:31
add comment

Using the David Carlisle's suggestion, here's a way. Adjust the argument to \vspace* to suit. The problem with the position of the first line is caused by the added \parskip before a paragraph, that can be corrected by inserting \vspace{-\parskip}.

Notice that the rule must be placed in the \parbox forming the first header.

\documentclass[]{scrartcl}

\newcommand{\longfirstpagehead}{%
\parbox[t][0pt]{\textwidth}{
some\\long\\text\\text\\text\\text\\text\\text
\par\kern1ex\hrule height1pt}%
}
\newcommand{\normalhead}{normal}
\usepackage{scrpage2}

\newpagestyle{firstpage}{%
{\longfirstpagehead} %twoside links
{\longfirstpagehead} %twoside rechts
{\longfirstpagehead} %oneside
(\textwidth,0pt)
}{%
{\pagemark\hfill} %twoside links
{\hfill\pagemark} %twoside rechts
{\hfill\pagemark} %oneside
} %

\newpagestyle{normal}{%
{\normalhead\hfill} %twoside links
{\normalhead\hfill} %twoside rechts
{\normalhead\hfill} %oneside
(\textwidth,1pt)
}{%
{\pagemark\hfill} %twoside links
{\hfill\pagemark} %twoside rechts
{\hfill\pagemark} %oneside
} %

\pagestyle{normal}
\AtBeginDocument{%
\thispagestyle{firstpage}%
\vspace*{7\baselineskip}%
\vspace{-\parskip}%
}

\usepackage{blindtext}

\begin{document}
\blindtext[8]
\end{document}

-
thx, with \vspace{-\parskip} it works very nice. I just have some questions. Any reason for \kern instead of vspace? Can I suppress this overfull hbox warning? –  someonr Feb 1 '12 at 23:33
It's caused by the \parbox; the easiest way is to say \parbox[t][0pt]{...}: I'll correct it. –  egreg Feb 1 '12 at 23:43
add comment