Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My purpose is that

  1. every page except title page has same header and footer.
  2. for title page,
    ==> it has exactly same footer with that of other page.
    ==> and it has completely different header with that of other page.

By default, title page will switch to plain pagestyle. Then we can define whatever in it. In my case, since title page has same footer with that of other page, I first define a pagestyle for whole article, then redefine a different header in title page. This header is only local to title page and won't influence the header of other pages.

After defining my own header leftheadertitlepage for title page, the footer of title page disappeared. If I used fancyhdr's header, e.g., \fancyhead[L]{whatever}, the footer of title page will be there as I desire. In both cases, the header and footer for other pages are OK. So how to make title page have my own header and a general footer of whole article?

Following is a small example. Please help check.

\documentclass[titlepage,a4paper]{article}

\usepackage{calc}
\usepackage[demo]{graphics}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0.4pt}
\rfoot{\thepage}
\cfoot{}

\begin{document}

\begin{titlepage}
\thispagestyle{fancy}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}

\newcommand\leftheadertitlepage{%
\begin{tabular}[b]{@{}l}
\begin{minipage}[b]{0.6\textwidth}
\includegraphics{test} 
\end{minipage}
Energietechnik GmbH \\
Gesch\"{a}ftsbereich\\
Energietechnik\\
\end{tabular}
}
\settototalheight\headheight{\maxof{\leftheadertitlepage}}
\lhead{\leftheadertitlepage}

\textbf{\Huge{title page}}
\pagebreak
\end{titlepage}
\lhead{}
\chead{demo}
whatever
\newpage
demo

\end{document}

With the help from Seamus and Matthew, I agree with Seamus's suggestion:

====================>
In title page, first, use the default pagestyle plain, then define the large image at the top that makes it look like a header. Finally, restore the pagestyle fancyhdr to make its footer exactly same with that of other pages.
<====================

Following is the updated code:

\documentclass[titlepage,a4paper]{article}

\usepackage{calc}
\usepackage[demo]{graphics}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0.4pt}
\rfoot{\thepage}
\cfoot{}

\begin{document}

\begin{titlepage}
% by default, the pagestyle of title page is plain
\renewcommand{\headrulewidth}{0pt} % cancel out the decorative line

\newcommand\leftheadertitlepage{%
\begin{tabular}[b]{@{}l}
\begin{minipage}[b]{0.6\textwidth}
\includegraphics{test} 
\end{minipage}
Energietechnik GmbH \\
Gesch\"{a}ftsbereich\\
Energietechnik\\
\end{tabular}
}

\newlength{\temp}
\settototalheight\temp{\maxof{\leftheadertitlepage}}
\vspace*{-\temp} % make the below image move up, then it looks like a header

\leftheadertitlepage % define the large image and put it at the top

\textbf{\Huge{title page}}
\thispagestyle{fancy} % restore fancyhdr pagestyle
\pagebreak
\end{titlepage}
\lhead{}
\chead{demo}
whatever
\newpage
demo

\end{document}

In the end, thank Seamus and Matthew again.

share|improve this question
    
why do you need that title page only header to be a header? Why not just put the image at the top of the title page? –  Seamus Apr 1 '11 at 10:45
    
@Seamus: I didn't understand your meaning "title page only header to be a header". For my title page, it has not only header but also footer. The title page's pagestyle is not plain but fancyhdr(see above text why it is fancyhdr). In this case, putting image at the top will put it below header and at the top of title page. So we waste the space of header. –  warem Apr 1 '11 at 11:12
    
yes I understand that you're forcing the title page to have fancy style. I don't think that's a good idea. Why not just redefine the plain page style? You can always add negative vspace to move your picture up if the problem is that it's not high enough... –  Seamus Apr 1 '11 at 11:14
    
Please use asterisks *like this* for emphasis, double-asterisks **like this** for boldface, and backticks like this only for code. –  Matthew Leingang Apr 1 '11 at 12:06
    
@Seamus: I finally take your suggestion that using default pagestyle for title page. I have added updated code accordingly. Thank you. I should say I have misunderstood something about title page environment. –  warem Apr 2 '11 at 3:51
add comment

3 Answers

The problem is that \leftheadertitlepage is defined only within the titlepage environment, while \lhead sets an interal macro globally. So after of the titlepage fancyhdr wants to but \leftheadertitlepage in the left head but doesn't know what that means anymore! Hence the undefined control sequence error.

To fix this, move the definition of \leftheadertitlepage to thepreamble. Then it will compile without difficulty. But you will also find the code from \leftheadertitlepage on pages after the title page. To shut that off just put \lhead after the titlepage is over.

Here is your rearranged file:

\documentclass[titlepage,a4paper]{article}

\usepackage{calc}
\usepackage[demo]{graphics}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0.4pt}
\fancyfoot[R] {\thepage}
\fancyfoot[C] {}

\newcommand\leftheadertitlepage{%
\begin{tabular}[b]{@{}l}
\begin{minipage}[b]{0.6\textwidth}
\includegraphics{test} 
\end{minipage}
Energietechnik GmbH \\
Gesch\"{a}ftsbereich\\
Energietechnik\\
\end{tabular}
}

\begin{document}

\begin{titlepage}
\thispagestyle{fancy}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}

\settototalheight\headheight{\maxof{\leftheadertitlepage}}
\lhead{\leftheadertitlepage}

title page
\pagebreak
\end{titlepage}
\lhead{}% to shut off the placement of `\leftheadertitlepage`

whatever

\end{document}

I'm not sure what it is you exactly want on the title page, but this allows to the document to compile without errors so you can take it to the next step.

share|improve this answer
    
According to your comment, I updated the code in my original text. Thank you. Please also read my updated text to know my purpose. –  warem Apr 1 '11 at 2:36
add comment

OK, I decided to add this as another answer because my first answer is really in response to the error you got the first time you posted.

The article class switches the current pagestyle to empty within the titlepage environment. So any pagestyle changes you make outside of the environment will be eliminated after \begin{titlepage}. This means you could make a custom fancy pagestyle titlepage and use it within your title page:

\fancypagestyle{titlepage}{
   %\settototalheight{\headheight}{\maxof{\leftheadertitlepage}}
   \renewcommand{\footrulewidth}{0.4pt}
   \lhead{\leftheadertitlepage}
   \chead{}
   \rhead{}
   \cfoot{}
   \rfoot{\thepage}
}

\begin{document}

\begin{titlepage}
\thispagestyle{titlepage}
\textbf{\Huge{title page}}
\end{titlepage}

% etc.

You will see your custom header on the title page with the fancy footer identical to the one you defined in the fancy pagestyle, and your fancy pagestyle on the other pages. You won't see the words "title page", though, and it's because they are behind the big black box standing in for your graphic.

The problem is that this header is way too tall. The fancyhdr package complains about that in the console:

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

We don't actually notice that change in the \headheight, maybe because this page style is only in force for this page? Anyway, you must have noticed that because you had this line in your code:

\settototalheight{\headheight}{\maxof{\leftheadertitlepage}}

This makes \headheight big enough to hold the box created by \leftheadertitlepage. If you insert this into your \fancypagestyle{titlepage}{... declaration (uncommenting it in the snippet above), you will eliminate the warning, and you will now see "title page" on the title page.

But you won't see your custom footer. Why? It didn't "disappear", it's below the edge of the page. The reason is that you've increased \headheight but you have not decreased the other layout parameters, and the logical page is now too tall to fit on on the physical page. You can see this by inserting dummy text on the title page; it will run all the way off the bottom.

So you need to subtract from \textheight the amount you add to \headheight. You can do this by adding:

\newlength{\originalheadheight}
\setlength{\originalheadheight}{\headheight}

in the preamble and then

\settototalheight{\headheight}{\maxof{\leftheadertitlepage}}
\addtolength{\textheight}{-\headheight}
\addtolength{\textheight}{\originalheadheight}   

somewhere else. But now we have another problem: you can't do this within the titlepage environment or the \fancypagestyle{titlepage} block. This is because

  1. changes to \textheight don't take effect until the next page.
  2. the changes to \headheight are forgotten after the group containing the \fancypagestyle{titlepage} code ends.

If you try to put this in the preamble you get something completely different and this is because the height of the \leftheadertitlepage depends on the context it's expanded in and so is different in the preamble than in the header. In the preamble \leftheadertitlepage takes up a box 827pt high.

So now what? Here, finally, is my solution. It requires a trial run to find out how high the header on the title page needs to be. Then you have to hard-code that in. Unless there's another way to set the \leftheadertitlepage box as if it were in the header when it's actually in the preamble, I don't know how else to do it. Then the adjustments to \textheight are done in the preamble, and have to be undone in the document text. The final wrinkle is that they have to be undone twice. Once within the titlepage environment, which will only affect the next page. Then once after the titlepage environment, which will affect the rest of the pages.

\documentclass[titlepage,a4paper]{article}
\usepackage{calc}
\usepackage[demo]{graphics}

\usepackage{lipsum}% just for dummy text, not part of solution.

\usepackage{fancyhdr}
\renewcommand{\footrulewidth}{0.4pt}
\lhead{}
\chead{demo}
\cfoot{}
\rfoot{\thepage}
\pagestyle{fancy}

\newcommand{\leftheadertitlepage}{
   \begin{tabular}[b]{@{}l}
      \begin{minipage}[b]{0.6\textwidth}
         \includegraphics{test} 
      \end{minipage}
      Energietechnik GmbH \\
      Gesch\"{a}ftsbereich\\
      Energietechnik\\
   \end{tabular}}


\makeatletter
\newlength{\originalheadheight}
\setlength{\originalheadheight}{\headheight}
\newlength{\titlepageheadheight}
\setlength{\titlepageheadheight}{127.60004pt}% has to be hard coded.
%\settototalheight{\headheight}{\maxof{\leftheadertitlepage}} will not work in this context
\addtolength{\textheight}{-\titlepageheadheight}
\addtolength{\textheight}{\originalheadheight}   
\makeatother


\fancypagestyle{titlepage}{
% uncommenting this line eliminates a warning, but also
% adds too much vertical space to the page.  So comment it out, record the number in the warning,
% then enter it above
   \setlength{\headheight}{\titlepageheadheight}
   \renewcommand{\footrulewidth}{0.4pt}
   \lhead{\leftheadertitlepage}
   \chead{}
   \rhead{}
   \cfoot{}
   \rfoot{\thepage}
}


\begin{document}
\begin{titlepage}
\thispagestyle{titlepage}
\textbf{\Huge{title page}}
%\lipsum[1-6]
% restore \textheight to its original--this will only happen on the next page
% because of the group within the titlepage environment
\addtolength{\textheight}{\titlepageheadheight}
\addtolength{\textheight}{-\originalheadheight}   
\end{titlepage}
% restore \textheight to its original--this will happen from the next page on
\addtolength{\textheight}{\titlepageheadheight}
\addtolength{\textheight}{-\originalheadheight}   

\lipsum
\lipsum

\end{document}

After all of this I agree with Seamus. A one-off pagestyle with taller header is probably better achieved with one-off code at the top of the page with an empty header.

share|improve this answer
    
Thank you for your clear explanation. In my real title page, the image is not that high, but there are many other items in title page. The total height is still taller than that of one physical page and the footer is nudged down off the bottom of the page. Since my tex code is generated by my C program, I can't (or don't) want to adjust headheight manually(this is also the reason why I add \settototalheight{\headheight}), the only way I can do is to hard-code all elements in title page to make them all appear. Anyway, thank you for your concept explanation. –  warem Apr 2 '11 at 0:36
    
I finally take Seamus's suggestion that using default pagestyle for title page. I have added updated code accordingly. It is your explanation that makes me understand something about title page environment. Thank you again. –  warem Apr 2 '11 at 3:54
add comment

OK. To fix the problem of the footer disappearing all you need to do is remove the \settototalheight\headheight{\maxof{\leftheadertitlepage}} line.

What this appears to be doing is nudging the footer off the bottom of the page. To see this, add \cfoot{\vspace{-5cm}FOOO} to your preamble. You'll see that the text appears, but nudged down by the amount defined above.


KOMA script offers nice facilities to define headers and footers that can differ on the first page of a chapter. Here's an example of how to get the same footer on each page, and a different header for the title page:

\documentclass{scrbook}
\usepackage{scrpage2}
\pagestyle{scrheadings}
\chead[Titlepage header goes here]{Other page header goes here}
\cfoot[Footer text]{Footer text}
\usepackage{lipsum}
\begin{document}
\chapter{The Chapter}
\lipsum
\end{document}

This defines the centre header and footer. KOMA also offers \lfoot \rfoot etc for left or right footers/headers. And \ifoot and \ofoot for "inside" and "outside" footers: these will change depending on whether it's an odd or an even page (doesn't work in scractrl class, or if you use the oneside option.

See p.64 ff. of the KOMA manual

If you can't use KOMA classes, for whatever reason, there here are soem general comments. The title page will by default, switch to the plain pagestyle. So what you should really do, instead of forcing the title page style to your own style, is redefine the plain footer and plain header to be what you want. That is, redefine the plain footer to be the same as your normal page style, and redefine the plain header to be your custom maguffin.

But having now seen Matthew's answer and the compiled code, I'm not sure why you want to put that stuff as a header rather than just put the tabular, picture and so on in a minipage at the top of your title page. That is, leave the plain footer empty and just put the image at the top of your title page...

share|improve this answer
    
@Seamus: Please read my updated text. –  warem Apr 1 '11 at 3:15
    
@Seamus: It is a way that you can define header and footer for title page when it is in plain style. But, in my case, the footer of title page is exactly same with that of other pages. So why should I repeat making footer? Another way is that I force title page to use the default fancyhdr pagestyle. This will guarantee the footer of title page is exactly same with that of other pages. Then what I only need to do is just to redefine the header of title page. –  warem Apr 1 '11 at 11:26
    
@Seamus: From technical reason, I really want to know why the footer of title page disappears when using fancyhdr in title page. –  warem Apr 1 '11 at 11:46
    
@warem I think the problem is that redefining \headheight pushes the footer off the bottom of the page. –  Seamus Apr 1 '11 at 12:21
2  
@warem I think I have fixed that problem (see new edit). If you really need to move the header around, don't do it by messing with \headheight but by adding some negative vspace above your minipage. –  Seamus Apr 1 '11 at 12:26
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.