Page LayoutFancy header with Table of Contents

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
isharp2
Posts: 23
Joined: Fri Feb 11, 2011 2:06 am

Fancy header with Table of Contents

Post by isharp2 »

Hi,
I am writing a thesis and my table of contents title, must say "TABLE OF CONTENTS" on page 1, and "TABLE OF CONTENTS (continued)" for every page thereafter.

After thinking about this for the past 12 hours, I had the idea to use 'fancyhdr', since it intrinsically puts headings on the second page. It was my hope that I could put a centered heading in the place of where I would want "TABLE OF CONTENTS (continued)" to be.

However, the way I have it right now, fancyhdr does not print footers or headers on the table of contents page. Is it possible to change this? code below:

Code: Select all

\usepackage{fancyhdr}
\setlength{\headheight}{15pt} %Required by fancyhdr
\renewcommand{\headrulewidth}{0pt}%Get rid of the horizontal line up top
\renewcommand{\refname}{ }%Make the title for the reference section blank... because the '\section' puts the title 'REFERENCES' in already.
\doublespacing

\begin{document}
\pagestyle{empty}

\pagenumbering{roman} %The acknowledgments and table of contents must be in roman numerals

\rhead{Right top}
\chead{Middle top}
\lhead{Left top}
\rfoot{Right bottom}
\cfoot{\thepage}
\lfoot{Left bottom}

\tableofcontents


thanks

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

5gon12eder
Posts: 126
Joined: Sun Feb 13, 2011 8:36 pm

Fancy header with Table of Contents

Post by 5gon12eder »

You don't get any of your headings because you say \pagestyle{empty} for all of your document. The fancyhdr package by default only defines the page style fancy.

Am I right that you only want roman page numbers for the front matter but not the whole document?

Here is an example how you could do it:

Code: Select all

\documentclass[twoside, titlepage]{article}% or whatever...

\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{blindtext}% used to generate random text

% needed for the page style definitions:
\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{afterpage}

% define page style ``fancy''
\fancyhead{}
\fancyhead[RO,LE]{TABLE OF CONTENTS \lastxmark}
\fancyfoot{}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\title{Lorem Ipsum}
\author{Alice Foo \and Bob Bar}

\begin{document}
  \pagenumbering{roman}% roman page numbers and
  \pagestyle{plain}%     plain page style in front matter
  \maketitle
  \blindtext% whatever else is supposed to go before the TOC...

  \clearpage
  \pagestyle{fancy}% fancy page style in TOC
  \afterpage{\extramarks{}{(continued)}}
  \tableofcontents

  \clearpage
  \pagenumbering{arabic}% arabic page numbers and
  \pagestyle{plain}%      plain page styles in the rest of the
                   %      document (or whatever...)

  % random content:
  \Blinddocument
  \blinddocument
  \Blinddocument
  \blinddocument
  \Blinddocument
  \blinddocument
  \Blinddocument
  \blinddocument
  \Blinddocument
  \blinddocument
\end{document}
Best
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
User avatar
Stefan Kottwitz
Site Admin
Posts: 10330
Joined: Mon Mar 10, 2008 9:44 pm

Fancy header with Table of Contents

Post by Stefan Kottwitz »

Hi,

this code is not compilable. The document class is missing, and more. So it cannot be tested and fixed. Not every reader builds an example himself following your description, so there might be less answers.

This page is helpful: What is a minimal working example, it also helps in creating such examples, which nearly guarantee a solution.

For printing footers or headers on the table of contents page, I suggest using \fancypagestyle{plain}{...}. If you would have posted a compilable test case example, I would have posted working code. Perhaps it already helps though.

By the way, I don't see a reason to put a header with the title on the same page, where the title is already in the header within the body text.

Stefan
LaTeX.org admin
Post Reply