## LaTeX forum ⇒ Page Layout ⇒ Conditional Variation of Head Height Topic is solved

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
pjmiller_57
Posts: 20
Joined: Tue Nov 08, 2011 4:37 pm

### Conditional Variation of Head Height  Topic is solved

Hello All,

Am trying to use \ifthenelse from the ifthen package to vary the size of \headheight within a document. Would like this to be larger for the first page and then smaller (possibly at its defaults size) for each subsequent page.

I had thought I could accomplish this using code like the following.
\ifthenelse{\thepage=1}   {\setlength\headheight{72pt}}   {\setlength\headheight{0pt}}

Unfortunately, that's not working for some reason. Below is some code that, for the most part, replicates what I'm trying to do. Can anyone help me understand why the snippet of code above is not working, as well as what the code should look like? In the code below, there are some \iftenelse statements that do work, but I found I wasn't able to use the same approach to producing variable head heights.

I'd be interested in knowing if those \ifthenelse statements are well-specified, or if they are ugly but still functional.

Thanks,
Paul

cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm
The conditional
\ifthenelse{\thepage=1}       {\setlength\headheight{72pt}}       {\setlength\headheight{0pt}}

will be executed at the place you call it in the document and set the head height once depending on the current definition of \thepage. This leads me to a possible problem with your conditional: \thepage might be “i” when you use \pagenumbering{roman} or even something like -- page~1 --. A safer way would be
\ifthenelse{\value{page}=1}       {\setlength\headheight{72pt}}       {\setlength\headheight{0pt}}

You actually don't need ifthen for this test, though. It is easy to define one yourself:
% make @ a letter:\makeatletter\newcommand\ifpageone{%   \ifnum\value{page}=1     % use only the first of two following arguments,     % \expandafter is necessary to let \@firstoftwo     % only act after \fi has been expanded:     \expandafter\@firstoftwo   \else     % use only the second of two following arguments     \expandafter\@secondoftwo   \fi}\makeatother

You can use this to set a new head height for example by setting it in the empty footer you're using:
\cfoot{\iffirstpage{\global\setlength\headheight{13pt}}}

Please note that \global is necessary here since otherwise this would change the length only within the scope of the footer. All in all this feels a bit hacky but it works.

A few additional remarks to your code: I would set the page geometry with the package geometry rather than set things by hand. I also wouldn't call the driver pdftex as »hyperref« package option. It is quite able to detect the right driver itself. The head height 72pt is too less for the current setting. I get the following warning:
Package Fancyhdr Warning: \headheight is too small (72.0pt):   Make it at least 76.76665pt.

Regards.
site moderator & package author

pjmiller_57
Posts: 20
Joined: Tue Nov 08, 2011 4:37 pm
Hi Clemens,

Thanks for your response. I tried the two pieces of code you supplied. Unfortunately, neither of them seemed to work for me.

The revised \ifthenelse statement seemed to set the header at page 1, much like you suggested my original \ifthenelse statement was doing.

The code that started with \makeatletter produced an error having to do with an undefined control sequence. Before testing this code, I commented out the \setlength\headheight{72pt} in the preamble as well as the empty \cfoot{}. Then immediately below the commented \cfoot{}, I pasted the \makeatletter code and the new line for \cfoot.

The error looked like this:
! Undefined control sequence.\f@ncyocf ->\iffirstpage                           {\global \setlength \headheight {78pt}}\strut l.87 \newpage [1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}]! Undefined control sequence.\f@ncyocf ->\iffirstpage                           {\global \setlength \headheight {78pt}}\strut l.91 \end{document}

Found what looks like a simple solution to my problem. Because I'll likely to set page breaks in my document manually, I can just change the \headheight after the first \newpage like below.
\begin{document} Some text \newpage\setlength\headheight{14pt} More text \end{document}

Might not be the most elegant solution generally, but should work well for my specific case.

Have noted your comments about the pdftex option in the hyperref package and the need to increase the head height from 72pt. Also took a quick look at the geometry package. This looks very useful. Will plan to learn the details as soon as I have time.

Appreciate your help with this. If you can help me understand why I wasn't able to implement your proposed solution, that would be great. If not though, I think I can make do with the very simple solution I proposed above.

Thanks,
Paul

cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm
The error is my fault: when I played with the code first I called the macro \iffirstpage but later decided to call it \ifpageone. I simply forgot to change the code I posted. I should read:

% make @ a letter:\makeatletter\newcommand\ifpageone{%   \ifnum\value{page}=1     % use only the first of two following arguments,     % \expandafter is necessary to let \@firstoftwo     % only act after \fi has been expanded:     \expandafter\@firstoftwo   \else     % use only the second of two following arguments     \expandafter\@secondoftwo   \fi}% make @ other again:\makeatother

and then later:
\cfoot{\ifpageone{\global\setlength\headheight{13pt}}}

If your manually setting the page break then setting a new head height manually is of course easier (and less hackish...)

Regards
site moderator & package author

pjmiller_57
Posts: 20
Joined: Tue Nov 08, 2011 4:37 pm
Hi Clemens,

Thanks for your most recent response. The code works now. I'll leave this question open for another day or so in case anyone else has any other solutions they'd like to share.

Thanks again.

Paul