0

I have finished my work and just optical adjustment: I want to remove any header/footer from Table of Contents, but not from the start of every chapter. I have found that \frontmatter and \mainmatter should do the trick, but that only achieved to remove any header/footer from page 2 (which was great).

with \documentclass[a4paper,12p,twoside]{book} I want to achieve:

i) Title page with only footer

ii) totally blank

iii) TOC - no header/footer

iv) TOC cont - no header/footer

page 1) Foreword - only footer

page 2) header/footer

etc.

Here is the code:

\documentclass[a4paper,12p,twoside]{book}
\usepackage[table]{xcolor}                   %% allow colour
\definecolor{Tmaroon}{RGB}{119,36,50}
\definecolor{Lblue}{RGB}{0,65,101}
\definecolor{Cgray}{RGB}{169,178,177}
\definecolor{Hyellow}{RGB}{242,223,116}

\usepackage[textwidth=450pt, textheight=680pt,top=3cm, left=2.5cm]{geometry} %margins
%
\setcounter{tocdepth}{1}
\usepackage{setspace}
\usepackage{soul}

\usepackage{titletoc}% http://ctan.org/pkg/titletoc
    \titlecontents{chapter}% <section-type>
      [0pt]% <left>
      {}% <above-code>
      {\bfseries\chaptername\ \thecontentslabel\quad}% <numbered-entry-format>
      {}% <numberless-entry-format>
      {\bfseries\hfill\contentspage}% <filler-page-format>

% dots for chapters
\usepackage{tocloft}
\renewcommand{\cftsecfont}{\scshape}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} % for chapters
\setlength\cftparskip{0pt}
\setlength\cftbeforechapskip{5pt}

\usepackage{fancyhdr}       %% allow header, footer
\setlength{\headheight}{15.2pt}
\pagestyle{fancy}
\fancyhf{} % clear header and footer fields
\fancyheadoffset{1 cm}
\fancyfootoffset{1 cm}
\lhead[\bfseries \textcolor{Lblue} {ST Handbook}]{}
\rhead[]{\textcolor{Tmaroon} {\leftmark}}
\lfoot[\textcolor{Cgray} {page \thepage}]{\textcolor{Cgray} {Chartered XXX}}
\rfoot[]{\textcolor{Cgray} {page \thepage}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}


\fancypagestyle{pchap}{ % pchap
    \fancyhf{}
    \fancyheadoffset{1 cm}
    \fancyfootoffset{1 cm}
    \lhead[]{}
    \rhead[]{}
    \lfoot[\textcolor{Cgray} {page \thepage}]{\textcolor{Cgray} {Chartered XXX}}
    \rfoot[]{\textcolor{Cgray} {page \thepage}}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0.4pt}
    } % pchap
\makeatletter
\let\ps@plain\ps@pchap
\makeatother


    \fancypagestyle{firstpage}{% first page different
    \lhead{}
    \chead{}
    \rhead{}
    \renewcommand{\headrulewidth}{0pt}
    \lfoot{\textcolor{Cgray} {Chartered XXX}}
    \rfoot{\bfseries \textcolor{Lblue} {ST}}
    \renewcommand{\footrulewidth}{0.4pt}
    }% first page different

\usepackage{datetime} % dates - my altered dates below
    \newdateformat{monthyeardate}{%
      \monthname[\THEMONTH] \THEYEAR} %just month written and Year
    
    \newdateformat{normal}{%
      \longdate \ordinaldate{\THEDAY} \monthname[\THEMONTH] \THEYEAR} %normal date
    
    \newcommand\twodigits[1] {\ifnum#1<10 0#1\else #1\fi}
    \newdateformat{quoteNo}{%
       \THEYEAR--\twodigits{\THEMONTH}--\twodigits{\THEDAY}} % digit date for quote no.

\setlength{\parindent}{0pt} % never indent first line

\usepackage{etoc}

\begin{document}

\frontmatter
\pagestyle{empty}

\pagenumbering{gobble}
\thispagestyle{firstpage}
    \begin{center}
    \vspace{0.9cm}
      { \bfseries \textcolor{Lblue} {\Huge{ST HANDBOOK}}}
    
    \vspace{15cm}
    
    {\footnotesize
     \hfill revised \normal \today \\
    }
    \end{center}

\cleardoublepage
%\thispagestyle{empty}
\doublespacing
\thispagestyle{firstpage}
\tableofcontents
\onehalfspacing
\thispagestyle{empty}
\cleardoublepage

\pagenumbering{arabic} 

\mainmatter
\pagestyle{fancy}

\chapter{ONE}

\section {A}

\chapter{TW0}

    \section {B}
    
    \newcount\cntas
    \loop
    \section{\the\cntas}
     soeoco \vspace{5cm} 
    \ifnum\cntas<20
    \advance\cntas 1
    \repeat

\newcount\cnta
\loop
\chapter{\the\cnta}
 soeoco \vspace{5cm} 
\ifnum\cnta<15
\advance\cnta 1
\repeat

\end{document}

Can I distinguish between \frontmatter and \mainmatter?

2 Answers 2

2

The problem with the Table of Contents is that it uses \thispagestyle{plain} as all Chapter opening pages do.

Adding \thispagestyle{empty} will not help: if you put it before \tableofcontents it will be overridden by the embedded \thispagestyle{plain}, and if you put it after, it will apply to the last page.

The trick is to sneak in a \thispagestyle{empty} as first element of the Table of Contents, which will be executed on the first page, but after the title (with its \thispagestyle{plain}) has been set up.

\newpage
\pagestyle{empty}
\addtocontents{toc}{\protect\thispagestyle{empty}}
\tableofcontents
\newpage
0

I have found one possible work around (not sure if efficient, but it does it for my work):

Replace

\makeatletter
\let\ps@plain\ps@pchap
\makeatother

with

\makeatletter
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                \if@mainmatter
                  \thispagestyle{pchap}% plain page style in mainmatter
                \else
                  \thispagestyle{empty}% empty page style outside of mainmatter
                \fi%
                \global\@topnum\z@
                \@afterindentfalse
                \secdef\@chapter\@schapter}
\makeatother

I would love to hear if there is a better solution/structure to my work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .