Document Classesfancyhdr and table of contents and page numbering

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
darckhart
Posts: 34
Joined: Mon Jul 09, 2007 4:04 am

fancyhdr and table of contents and page numbering

Post by darckhart »

Sorry for the long post in advance... there's snippets of code I wanted to show.

I did a quick search for table of contents and fancyhdr problems, but found nothing related, so here goes.

I am having a bit of trouble with numbering. I am using the fancyhdr package to add headers and footers. All my front matter pages should be roman numeral and centered at bottom. Main matter pages should be arabic numeral and in top right.

In addition to the plain style, I defined two new styles.

I have defined a new fancy style I called fancyplain style like so for the front matter pages

Code: Select all

Code, edit and compile here:
\fancypagestyle{fancyplain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\thepage} % except the center
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I have defined a new fancy style I called fancy style like so for the main matter pages

Code: Select all

Code, edit and compile here:
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{\thepage}
\lfoot{DRAFT}
\cfoot{}
\rfoot{\today}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I called them in my document like so:

Code: Select all

Code, edit and compile here:
\thispagestyle{plain}
\include{abstract}
\chapter*{Acknowledgements}
I would like to thank \ldots
%------------ Table of Contents ------------------------------
\thispagestyle{fancyplain}
\renewcommand{\contentsname}{Table of Contents}
\tableofcontents{}
%\addcontentsline{toc}{chapter}{Table of Contents}
%------------ List of Tables ---------------------------------
\thispagestyle{fancyplain}
\listoftables{}
\addcontentsline{toc}{chapter}{List of Tables}
%------------ List of Figures --------------------------------
\thispagestyle{fancyplain}
\listoffigures{}
\addcontentsline{toc}{chapter}{List of Figures}
%------------ Acronyms List ----------------------------------
\thispagestyle{fancyplain}
\chapter*{List of Acronyms}
\addcontentsline{toc}{chapter}{List of Acronyms}
\begin{acronym}
\acro[html]{hypertext markup language}
\end{acronym}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The results are:
abstract page with no header and footer GOOD
acknowledgments page with centered footer roman numeral GOOD (but not sure how that worked)
TOC page with no header and footer BAD
LOT page with centered footer roman numeral GOOD
LOF page with centered footer roman numeral GOOD
LOA page with no header and footer BAD

How can I get the page number of the Table of Contents page to show? The TOC page is vi and should show up in the center footer, but doesn't. Same problem with the List of Acronyms page, which should be x, but doesn't show.

TIA.

Recommended reading 2024:

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

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

fancyhdr and table of contents and page numbering

Post by gmedina »

I'm confused:
darckhart wrote: TOC page with no header and footer BAD...
LOA page with no header and footer BAD

However, you explicitly define and use in the TOC and in the LOA a page style that removes headers and footers (except for the page number in the center of the footer):
darckhart wrote:

Code: Select all

Code, edit and compile here:
\fancypagestyle{fancyplain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\thepage} % except the center
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

At this point I don't know exactly what you want.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
darckhart
Posts: 34
Joined: Mon Jul 09, 2007 4:04 am

fancyhdr and table of contents and page numbering

Post by darckhart »

\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\thepage} % except the center

Thus, fancyplain style commands should yield blank header and centered footer with roman numeral. It does this correctly on both LOT page and LOF page, but not on TOC page and LOA page even though I am asking it to apply fancyplain to all four pages.

My question is why does it seem to disregard the explicit \thispagestyle{} commands for these pages. I am guessing it has something to do with the autogeneration of the content on those pages and latex doesn't know exactly where the pages end until it compiles through to the end of the document. I tried using \clearpage or \newpage after the call for the various pages (e.g., \listoffigures{}\clearpage), but that didn't work either. It would either still make blank header and footer, or apply fancy style.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

fancyhdr and table of contents and page numbering

Post by gmedina »

darckhart wrote: Thus, fancyplain style commands should yield blank header and centered footer with roman numeral. It does this correctly on both LOT page and LOF page, but not on TOC page and LOA page even though I am asking it to apply fancyplain to all four pages.

My question is why does it seem to disregard the explicit \thispagestyle{} commands for these pages. I am guessing it has something to do with the autogeneration of the content on those pages and latex doesn't know exactly where the pages end until it compiles through to the end of the document. I tried using \clearpage or \newpage after the call for the various pages (e.g., \listoffigures{}\clearpage), but that didn't work either. It would either still make blank header and footer, or apply fancy style.



Still don't see what is your problem, but try the following MWE:

Code: Select all

Code, edit and compile here:
\documentclass{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancypagestyle{fancyplain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\thepage} % except the center
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{\thepage}
\lfoot{DRAFT}
\cfoot{}
\rfoot{\today}
\begin{document}
%------------ Frontmatter -----------------------------------
\frontmatter
\chapter*{Acknowledgements}
I would like to thank \ldots
%------------ Table of Contents ------------------------------
\thispagestyle{fancyplain}
\renewcommand{\contentsname}{Table of Contents}
\tableofcontents
\addcontentsline{toc}{chapter}{Table of Contents}
%------------ List of Tables -----------------------------------
\thispagestyle{fancyplain}
\listoftables
\addcontentsline{toc}{chapter}{List of Tables}
%------------ List of Figures ----------------------------------
\thispagestyle{fancyplain}
\listoffigures
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Edit: in fact, the above code is redundant, the \thispagestyle{fancyplain} commands are not needed, since the \frontmatter command takes charge of the roman numbering in the center of the foot.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
darckhart
Posts: 34
Joined: Mon Jul 09, 2007 4:04 am

Re: fancyhdr and table of contents and page numbering

Post by darckhart »

Hi thanks again for your reply and patience. However, i believe that the commands \frontmatter and \mainmatter are not available in the report type class and work only in the book type class.

I have figured out why the LOA page does not have the correct footer style and that is because it is the \chapter command that makes that particular page "special." I now think that this is the same reason why the footer does not show up on the TOC page. When I execute a \clearpage command after each (e.g., \listoffigures{}\clearpage), this also makes the page "special" and the footers will not show up.

Hm ok after a bit more fiddling I notice that all the Chapter title pages do not have headers nor footers. Is there a way to override this behavior and force headers and footers to show even on pages generated with the \chapter command?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

fancyhdr and table of contents and page numbering

Post by gmedina »

darckhart wrote: Hm ok after a bit more fiddling I notice that all the Chapter title pages do not have headers nor footers. Is there a way to override this behavior and force headers and footers to show even on pages generated with the \chapter command?


Yes, there is a way: write

Code: Select all

\thispagestyle{fancy}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
immediately after each \chapter command.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jobi
Posts: 1
Joined: Tue Aug 26, 2008 3:11 pm

fancyhdr and table of contents and page numbering

Post by jobi »

Here is a solution you may try, I found it while reading your posts :

Code: Select all

\tableofcontents{\thispagestyle{fancyplain}}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
And for all of your chapter to be identical to the remaining of the text, you can either write

Code: Select all

\thispagestyle{fancy}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
after the chapter commande
or

Code: Select all

\pagestyle{fancy},
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
and thus fixing the style of the headers. You may put it in the preambule, but also in your text, if you want to change style in the middle of your report...
esther
Posts: 5
Joined: Wed Aug 27, 2008 6:35 pm

fancyhdr and table of contents and page numbering

Post by esther »

jobi wrote:Here is a solution you may try, I found it while reading your posts :

Code: Select all

\tableofcontents{\thispagestyle{fancyplain}}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This didn't work for me. But as suggested by Thorsten in another related post, the command \fancypagestyle described in section 7 of the fancyhdr documentation allows to do the job.

I had another related problem: the white page before the TOC (and the bibliography) had the fancy style while I wanted it to be blank. The solution I found was to add a \newpage at the end of the previous chapter/section and to add the command \thispagestyle{empty} for this new page.
Post Reply