2

I am using packages fancyhdrand fancyto customize header and footer.

.....
\usepackage{fancyhdr} 
\pagestyle{fancy}
\lhead{Team no.}
\rhead{Problem no.}
\cfoot{Page \thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}
\title{Problem Name}
\author{Team no. \\ Problem no.}
\maketitle
\pagenumbering{gobble}
\begin{abstract}
\end{abstract}
\newpage
\tableofcontents
\newpage
\pagenumbering{arabic}
\section{Introduction}
....

I wanna remove only the footer(here 'page number') from the 'table of contents' pages. Also, I like to use 'page number' in the format of "Page x of y". How can I do?
TIA

5
  • All of the pages with the \tableofcontents should have its page number removed?
    – Werner
    Oct 22, 2018 at 19:56
  • You second question is answered here: How can I add "page # of ##" on my document?
    – Werner
    Oct 22, 2018 at 19:56
  • yes, @Werner . All of the pages with the \tableofcontents should have its page number removed.
    – raf
    Oct 22, 2018 at 20:03
  • What \documentclass are you using?
    – Werner
    Oct 22, 2018 at 20:18
  • \documentclass[a4paper,12pt]{article}
    – raf
    Oct 22, 2018 at 20:21

2 Answers 2

3

For some reason I had trouble turning \pagestyle{fancy} off and on again. It was easier to create two new pagestyles instead.

\documentclass[a4paper,12pt]{article} 
\usepackage{fancyhdr} 

\fancypagestyle{nofoot}{%
  \fancyhf{}% clear all header and footer fields
  \lhead{Team no.}
  \rhead{Problem no.}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
}
\fancypagestyle{foot}{%
  \fancyhf{}% clear all header and footer fields
  \lhead{Team no.}
  \rhead{Problem no.}
  \cfoot{Page \thepage}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
}
\usepackage{lipsum}

\begin{document}
\title{Problem Name}
\author{Team no. \\ Problem no.}
\maketitle
\pagenumbering{gobble}
\begin{abstract}
\end{abstract}
\newpage
\pagestyle{nofoot}
\tableofcontents
\newpage
\pagestyle{foot}
\pagenumbering{arabic}
\section{Introduction}
\lipsum[1-6]
\end{document}
5
  • This solution isn't affected by \pagestyle{fancy}, right?.
    – raf
    Oct 23, 2018 at 7:23
  • 1
    \pagestyle{fancy} seems to have no effect whatsoever. Oct 23, 2018 at 13:28
  • Can you please tell me how to bookmark the 'table of contents' page so that I can return to the content page easily? (according to your given answer) @John Kormylo
    – raf
    Mar 28, 2020 at 6:41
  • Bookmarking the TOC really has nothing to do with page style. If you are using hyperref, just use \hypertarget (possibly with \addtocontents or \contentsname) and \hyperlink. Mar 28, 2020 at 19:54
  • Ok. I am doing it in this way: tex.stackexchange.com/a/65547/114006
    – raf
    Mar 30, 2020 at 5:01
1

Here is another suggestion using \pagestyle{fancyplain} after loading package fancyhdr. Then both pagestyles fancy and plain under control of fancyhdr and \fancyplain{settings for plain style}{settings for fancy style} can be used in the argument of \fancyhf, \fancyhead etc.

\documentclass[a4paper,12pt]{article}
\setlength{\headheight}{14.5pt}% <- suggested by fancyhdr
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancyplain}

\fancyhf{}
\fancyhead[L]{Team no.}
\fancyhead[R]{Problem no.}
\fancyfoot[C]{\fancyplain{}{Page \thepage\ of \pageref{LastPage}}}% no pagenumber on plain pages
\renewcommand{\headrulewidth}{0pt}

\usepackage{lipsum}% only for dummy text
\begin{document}
\pagestyle{plain}
\pagenumbering{roman}

\title{Problem Name}
\author{Team no. \\ Problem no.}
\maketitle
\thispagestyle{empty}
\begin{abstract}
\lipsum[1]
\end{abstract}

\clearpage
\tableofcontents
\clearpage
\pagestyle{fancy}
\pagenumbering{arabic}
\section{Introduction}
\lipsum[1-6]
\end{document}

Result:

enter image description here

0

You must log in to answer this question.

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