Page LayoutDifferent Headers/Footers per Page

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
apollo_el
Posts: 9
Joined: Sat Sep 17, 2011 12:16 am

Different Headers/Footers per Page

Post by apollo_el »

Hello all,

First of all, I'd like to say that I have been trying to solve this for the last 2 days, w/o any success. I would like to be able to have a header at my first page (centered with the line underneath) and a footer at the same page (centered). For all other pages, I would like to have just a header (to the right), which is different than the first one. Could anyone please advice me how to proceed? I'm totally lost.

Is there a simple way with the package fancyhdr to have different headers/footers at different pages? (not just even-odd). This is what I have tried:

Code: Select all

\usepackage{fancyhdr}  
\thispagestyle{fancy}
\renewcommand{\headrulewidth}{2pt} 
\chead{\textcolor{mycolor}{\Huge{\texttt{\textbf{here goes my text}}}}}
\cfoot{\textcolor{mycolor}{\underline{\textit{\textbf{Last Updated: \today}}}}}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}
\chead{} 
\rhead{\textcolor{mycolor}{\textit{\textbf{different text here}}}} 
\cfoot{}
Last edited by apollo_el on Sun Sep 18, 2011 11:29 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Different Headers/Footers per Page

Post by localghost »

You have to define several page styles by the \fancypagestyle command and later use them by the known \pagestyle command. Actually the fancyhdr manual is quite clear in this regard.


Best regards and welcome to the board
Thorsten
apollo_el
Posts: 9
Joined: Sat Sep 17, 2011 12:16 am

Different Headers/Footers per Page

Post by apollo_el »

Thank you for your help. The manual was not quite clear to me, at least, however I figured it out, based on what you said. For future reference, if anybody comes across this, here's what I did:

Code: Select all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PAGES 2-END 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0.3pt} 
\rhead{\textcolor{mycolor}{\textit{\textbf{My text goes here}}}} %header at the right


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FIRST PAGE ONLY (redefine via \fancypagestyle the plain pagestyle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fancypagestyle{plain}{
\fancyhf{}
\renewcommand{\headrulewidth}{5pt} 
\chead{\textcolor{mycolor}{\Huge{\texttt{\textbf{Different text here}}}}}
\cfoot{\textcolor{mycolor}{\underline{\textit{\textbf{Some text here}}}}}
}
Last edited by apollo_el on Sun Sep 18, 2011 11:28 pm, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Different Headers/Footers per Page

Post by localghost »

This code snippet is useless, thus represents no solution. It uses self-defined stuff and commands from other packages. A full example would be best to comprehend what you did. Finally your are not only writing here for yourself, but also for others.
apollo_el
Posts: 9
Joined: Sat Sep 17, 2011 12:16 am

Different Headers/Footers per Page

Post by apollo_el »

localghost wrote:This code snippet is useless, thus represents no solution. It uses self-defined stuff and commands from other packages. A full example would be best to comprehend what you did. Finally your are not only writing here for yourself, but also for others.

I could respond to this comment in many ways, however, for the best of humanity I choose to make things crystal clear, in the best possible way that I can:

The problem: I wanted to have one header in the first page of my doc and a different one in the remaining pages. Also, only one footer in the first page and nothing in the rest.

The solution: Redefine, via "\fancypagestyle", the plain pagestyle and later use it, when required. This is shown in the previous "useless" snippet.Then, when the document begins (that is, the first page of my doc, which I want it to be different than the rest):

Code: Select all

\begin{document}
\maketitle\thispagestyle{plain}
[/code]
we may call:

Code: Select all

\thispagestyle{plain}
, defined above with the
parameters that apply in each case ( for me it was a \chead and a \cfoot ). This way, we are asking latex to use
the pagestyle we have user-defined, for the first page only, in order to differ from the rest.

Now, for the rest of the pages in my doc, I used again the previous "useless" snippet, given in my previous post. So all in all, the code would like:

Code: Select all

\documentclass[whatever_here]{something_here}
.....
.....
.....
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% COMMANDS FOR OTHER PAGES HEADER/FOOTER GO HERE 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{as_u_prefer_here} 
\rhead{yada..yada...yada} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% COMMANDS FOR FIRST PAGE ONLY HEADER/FOOTER GO HERE (redefine via \fancypagestyle the plain pagestyle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fancypagestyle{plain}{
\fancyhf{}
\renewcommand{\headrulewidth}{as_u_prefer_here} 
\chead{bla..bla}
\cfoot{yada..yada}
}
User avatar
justdeath
Posts: 69
Joined: Mon Sep 05, 2011 10:27 am

Different Headers/Footers per Page

Post by justdeath »

As localghost stated, you should read the documentation:
ftp://ctan.tug.org/tex-archive/macros/l ... ncyhdr.pdf
Your solution is on page 13. And I did it for you:

Code: Select all

\documentclass{article}
\usepackage{fancyhdr}

\fancyhead{}
\fancyhead[L]{left header}
\fancyhead[R]{right header \quad \thepage}
\fancyfoot{}
\fancypagestyle{plain}{
	\fancyhead{}
	\fancyhead[C]{first page center header}
	\fancyfoot{}
	\fancyfoot[C]{first page center footer}
}
\pagestyle{fancy}

\begin{document}
\thispagestyle{plain}
This is the first page.
\newpage
This is the second page.
\newpage
This is the third page.
\end{document}
Please next time post a real WORKING example, not *whatever* things.

Nikolay
Post Reply