0

I am typesetting a document with Latex, in which I want the page numbers at right bottom. The following MWE works fine, except that the chapter title pages have number in the center.

\documentclass[12 pt, oneside]{extbook} %extarticle provides additional font-sizes

%formatting header and footer

\usepackage{fancyhdr}

\pagestyle{fancy}

\fancyhead{}

\fancyfoot{}

\fancyhead[CE, CO]{\scriptsize Qualitative Analysis of Sanskrit E-learning Systems}

\fancyfoot[RO, LE]{\thepage}

\usepackage[english]{babel}

\usepackage{blindtext}

\pagestyle{fancy}

\begin{document}

\frontmatter

\pagestyle{plain}

\blindtext[10]

\pagestyle{fancy}

\fancyhead[CE, CO]{\scriptsize Table of Contents}

\tableofcontents

\mainmatter

\pagestyle{fancy}

\fancyhead[CE, CO]{\scriptsize Chapter1}

\chapter{chapter1}

\blindtext[20]

\fancyhead[CE, CO]{\scriptsize Chapter2}

\chapter{chapter2}

\blindtext[20]

\end{document}

On searching to resolve this problem, I found this bit of code to redefine the plain pagestyle.

%Redefining plain style for chapter title pages

\fancypagestyle{plain}{

\fancyhf{}
     \fancyfoot[R]{\thepage}
    \renewcommand{\headrulewidth}{0pt}
}

But if I add this code, it removes header line (headrule) from all pages.

Here is the complete MWE

\documentclass[12 pt, oneside]{extbook} %extarticle provides additional font-sizes

%formatting header and footer

\usepackage{fancyhdr}

\pagestyle{fancy}

\fancyhead{}

\fancyfoot{}

\fancyhead[CE, CO]{\scriptsize Qualitative Analysis of Sanskrit E-learning Systems}

\fancyfoot[RO, LE]{\thepage}

%Redefining plain style for chapter title pages

\fancypagestyle{plain}{

\fancyhf{}
     \fancyfoot[R]{\thepage}
    \renewcommand{\headrulewidth}{0pt}
}

\usepackage[english]{babel}

\usepackage{blindtext}

\pagestyle{fancy}

\begin{document}

\frontmatter

\pagestyle{plain}

\blindtext[10]

\pagestyle{fancy}

\fancyhead[CE, CO]{\scriptsize Table of Contents}

\tableofcontents

\mainmatter

\pagestyle{fancy}

\fancyhead[CE, CO]{\scriptsize Chapter1}

\chapter{chapter1}

\blindtext[20]

\fancyhead[CE, CO]{\scriptsize Chapter2}

\chapter{chapter2}

\blindtext[20]

\end{document}

What do I do to retain headrule on pages other than the plain pages? (To clarify, I want plain pages with no header, but page numbers on the right bottom, fancy pages with header text, headrule, and page numbers on right bottom).

  • Using an odd/even (O/E) placement in oneside mode doesn't make sense; fancyhdr will warn you about this. – Werner Sep 23 '19 at 17:28
1

It's better to define two page styles; the one redefines plain while the other defines what should happen outside of the plain pages.

enter image description here

\documentclass[twoside]{extbook} %extarticle provides additional font-sizes

%formatting header and footer
\usepackage{fancyhdr}

\fancypagestyle{newpagestyle}{%
  \fancyhf{}% Clear header/footer
  \fancyhead[CE, CO]{\scriptsize Qualitative Analysis of Sanskrit E-learning Systems}
  \fancyfoot[RO, LE]{\thepage}
  \renewcommand{\headrulewidth}{.4pt}
}

\pagestyle{newpagestyle}% Set the default page style

%Redefining plain style for chapter title pages

\fancypagestyle{plain}{
  \fancyhf{}% Clear header/footer
  \fancyfoot[R]{\thepage}
  \renewcommand{\headrulewidth}{0pt}% Remove header rule
}

\usepackage[english]{babel}

\usepackage{blindtext}

\begin{document}

\frontmatter

\blindtext[10]

\tableofcontents

\mainmatter

\chapter{chapter1}

\blindtext[20]

\chapter{chapter2}

\blindtext[20]

\end{document}

Also, avoid setting the header before a call to \chapter, as in

\fancyhead[..]{...}
\chapter[..]{...}

Why? Because \chapter issues a \newpage which ships out the current page on which you've set header content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.