Remove Chapter title from header on all pages, latex book class - latex

Edited to include a reproducible example.
So, I've found a number of people asking about how to add the chapter title from the header of subsequent pages but I need the opposite. I'm using fancy header but need everything except the page number removed from the header (the page needs to be at the top right of every page). The code I'm using removes the header from the first page of each chapter, but every subsequent page has the chapter name in the header on the left. I'm using \documentclass[12pt,oneside]{book}.
Below is the header code:
\documentclass[12pt,oneside]{book}
\usepackage{fancyhdr} % Permits header customization. See header section below.
\fancypagestyle{plain}{
\lhead{}
\fancyhead[R]{\thepage}
\fancyhead[L]{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
}
\begin{document}
\chapter{Starting Here}
Some stuff
\newpage
New stuff
\end{document}
I have to submit this document with specific formatting requirements and want to continue using the fancyhdr package. Any help is much appreciated.

While your MWE loads the fancyhdr package, you don't actually use it for normal pages as there is no \pagestyle{fancy} or similar. This means your code only customises plain pages like they are used for the first page of a chapter.
If you want to customise normal pages as well:
\documentclass[12pt,oneside]{book}
\usepackage{fancyhdr} % Permits header customization. See header section below.
\fancypagestyle{plain}{
\lhead{}
\fancyhead[R]{\thepage}
\fancyhead[L]{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
}
\pagestyle{fancy}
\fancyhead[R]{\thepage}
\fancyhead[L]{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
\begin{document}
\chapter{Starting Here}
Some stuff
\newpage
New stuff
\end{document}

from the .cls file, I commented \pagestyle and added following code before /begin{document}.
\usepackage{fancyhdr} % Permits header customization. See header section below.
\fancypagestyle{plain}{
\lhead{}
\fancyhead[R]{\thepage}
\fancyhead[L]{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}
}
\pagestyle{fancy}
\fancyhead[R]{\thepage}
\fancyhead[L]{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}

Related

Adapt latex page header depending on situations

I added a page header with the following command in LaTeX:
\pagestyle{fancy} \fancyhead[L]{\rightmark} \fancyhead[R]{\leftmark}
Here is a minimal reproducible example:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\title{Titlepage}
\date{October 2021}
\pagestyle{fancy} \fancyhead[L]{\rightmark} \fancyhead[R]{\leftmark}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{lipsum} %just to generate text for the example
\newcommand*\HUGE{\Huge}
\newcommand*\chapnamefont{\normalfont\LARGE\MakeUppercase CHAPTER}
\newcommand*\chapnumfont{\normalfont\HUGE}
\newcommand*\chaptitlefont{\normalfont\HUGE\bfseries}
\newlength\beforechapskip
\newlength\midchapskip
\setlength\midchapskip{\paperwidth}
\addtolength\midchapskip{-\textwidth}
\addtolength\midchapskip{-\oddsidemargin}
\addtolength\midchapskip{-1in}
\setlength\beforechapskip{18mm}
\titleformat{\section}[display]
{\normalfont\filleft}
{{\chapnamefont}%
\makebox[0pt][l]{\hspace{.8em}%
\resizebox{!}{\beforechapskip}{\chapnumfont\thesection}%
\hspace{.8em}%
\rule{\midchapskip}{\beforechapskip}%
}%
}%
{25pt}
{\chaptitlefont}
\titlespacing*{\section}
{0pt}{40pt}{40pt}
\begin{document}
\maketitle
\newpage
blank page
\newpage
\section{Introduction}
the page header should not be visible here
\newpage
\subsection{Test2}
only the section should be visible in the page header (1 INTODUCTION)
\newpage
only the subsection should be visible in the page header (1.1 Test2)
\end{document}
With this command there is the problem that it appears on all pages, but for my thesis I would like to remove it from pages where the section shows up for the first time
here is an example how it currently looks:
this is how it should look like, when the section appears for the first time:
Also I would like the header to adapt, according to which side it is on (even or odd). For example I would want to have on the left page the section name only (even page) and on the right side the subsection name should show up (odd page):
I would use another documentclass. This would automatically solve most of your problems:
in report or book class, the first pages of a chapter automatically use another page style without the header
if you use a two-sided document, you can define the fancyhead depending on E(ven) or O(dd) pages
\documentclass[twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\title{Titlepage}
\date{October 2021}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[LE]{\leftmark}
\fancyhead[RO]{\rightmark}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{lipsum} %just to generate text for the example
\newcommand*\HUGE{\Huge}
\newcommand*\chapnamefont{\normalfont\LARGE\MakeUppercase CHAPTER}
\newcommand*\chapnumfont{\normalfont\HUGE}
\newcommand*\chaptitlefont{\normalfont\HUGE\bfseries}
\newlength\beforechapskip
\newlength\midchapskip
\setlength\midchapskip{\paperwidth}
\addtolength\midchapskip{-\textwidth}
\addtolength\midchapskip{-\oddsidemargin}
\addtolength\midchapskip{-1in}
\setlength\beforechapskip{18mm}
\titleformat{\chapter}[display]
{\normalfont\filleft}
{{\chapnamefont}%
\makebox[0pt][l]{\hspace{.8em}%
\resizebox{!}{\beforechapskip}{\chapnumfont\thechapter}%
\hspace{.8em}%
\rule{\midchapskip}{\beforechapskip}%
}%
}%
{25pt}
{\chaptitlefont}
\titlespacing*{\chapter}
{0pt}{40pt}{40pt}
\begin{document}
\maketitle
\newpage
blank page
\newpage
\chapter{Introduction}
the page header should not be visible here
\newpage
\section{Test2}
only the section should be visible in the page header (1 INTODUCTION)
\newpage
only the subsection should be visible in the page header (1.1 Test2)
\end{document}

Some pages are not numbered for me - let\clearpage\relax

I used \let\clearpage\relax to keep two chapters on one page and this is causing the page number on proceeding page not to be displayed.
Is there a way I can undo the command in the document and still keep two chapters one page?
More detail provided.
\documentclass[12pt,a4paper]{report}
\usepackage[left=3cm,right=3cm,top=-2cm,bottom=4cm]{geometry}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{placeins}
\usepackage{tocloft}
\usepackage{ifthen}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}
\usepackage{caption}
\captionsetup[table]{skip=10pt}
\pagestyle{fancy}
\usepackage{setspace}
\makeatletter
% addition for not showing 'Chapter 1'
\def\#makechapterhead#1{%
\vspace*{50\p#}%
{\parindent \z# \raggedright \normalfont
\interlinepenalty\#M
\Huge \bfseries
\ifnum \c#secnumdepth >\m#ne
\thechapter\nobreakspace
\fi
#1\par\nobreak
\vskip 40\p#
}}
\#ifundefined{chapter}%
{}%
{\renewcommand{\chaptermark}[1]{%
\ifthenelse{\value{chapter} < 1}%
{\markboth{#1}{}}%
{\markboth{\thechapter\ #1}{}}
}}
\addtolength{\headheight}{\baselineskip}
\renewcommand{\headrulewidth}{0.4pt} %% thin line under header
%\renewcommand{\headrulewidth}{0pt} %% no line under header
\renewcommand{\footrulewidth}{0pt}
\fancyhf{} %% Clear all fields.
%\fancyhead[LE,RO]{\sffamily\thepage}
%\fancyhead[LO,RE]{\sffamily\nouppercase{\leftmark}}
\fancyhead[R]{\sffamily\thepage}
\fancyhead[L]{\sffamily\nouppercase{\leftmark}}
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\sffamily\thepage} % except the center
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
\makeatother
The problem was caused by a combination of two factors:
you document uses different page styles for chapter pages and normal pages. On chapter pages, the page number had been at the bottom centre, on normal pages there was a header with the chapter title and the page number
you were using the geometry package with a large negative top margin. This pushed the header of normal pages off the page and you did no longer see the page number on them.
Proposed solution:
use a reasonable values for the page geometry, e.g. \usepackage[left=3cm,right=3cm,top=2cm,bottom=4cm]{geometry}
This also has the advantage, that one can remove most of the hard codes \vspaces in your figures and tables
if you'd like to remove the header and move the page number to the bottom centre on all normal pages, the following definitions can be used:
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\sffamily\thepage} % except the center
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

LaTeX - two pages "1" with package hyperref

When compiling a LaTeX document, I get two pages numbered at "1": the front page and the first of the table of contents. Here's a MWE:
\documentclass[12pt,a4paper]{report}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\title{Title}
\begin{document}
\maketitle
\tableofcontents
\chapter{Chapter one}
\end{document}
When compiling this (using simply pdflatex file.tex), I get this:
But when I remove the line \usepackage{hyperref}, page numbers are fine. Note that I need this package to have links to pages in my table of contents, but maybe there's a better way to do so. What is happening here ? How do I get normal page numbers ?
Thanks in advance.
\maketitle under the report class sets the page number to 1 on the title page, but also restarts it from 1 for the following page. That's why you achieve a virtual page number 1 for the title, followed by an actual page number one for the ToC. I emphasize virtual here because \maketitle sets the title on an empty page style so that nothing is printed in the header/footer. However, these page numbers still appear in the toolbar when viewed in Adobe Acrobat.
One way around it would be to manually change the page display to something more appropriate just for the title page. For example, let's make the title page be called T:
\documentclass{report}
\usepackage{hyperref}
\title{Title}
\author{Author}
\begin{document}
\begingroup
\renewcommand{\thepage}{T}
\maketitle % Page T
\endgroup
\tableofcontents % Page 1
\chapter{A chapter} % Page 2
\end{document}

The numbering of the sections appear only in the first section

I'm having a problem with the numbering of the sections in latex.
I want the numbering of the chapters and sections to be as
1 first chapter
1.1 first section
1.2 second section
the problem is that the numbering of the section appears only in the first section and I have no idea why is this happening!
this is the code that I used.
\documentclass [a4paper,12pt]{report}
\usepackage{times}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage[utf8]{inputenc} % for numbering of pages
\usepackage{ragged2e}
\usepackage{indentfirst}
\usepackage{setspace}
\usepackage{titlesec}
\usepackage[english]{babel}
\renewcommand\thesection{\arabic{section}} % for the chapters numbering
%margins
%1 inch from top, buttom and right side of the page and 1.5 inch from left side of the page
\geometry{
a4paper,
left=1.5in,right=1in,top=1in,bottom=1in
}
\onehalfspacing
\centering
\pagenumbering{roman}
\titleformat{\section}
{\normalfont\fontsize{16}{15}\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\fontsize{14}{15}\bfseries}{\thesection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\fontsize{12}{15}\bfseries}{\thesection}{1em}{}
\renewcommand{\thesection}{\thechapter.\number\numexpr\value{section}\relax}
\renewcommand{\thesubsection}{\thesection.\number\numexpr\value{subsection}\relax}
\renewcommand{\thesubsubsection}{\thesubsection.\number\numexpr\value{subsubsection}\relax}
\setcounter{secnumdepth}{3}
\setcounter{chapter}{1}% Not using chapters, but they're used in the counte
\begin{document}
% this is the table of contents of the document
\renewcommand*\contentsname{Table of Contents}
%--------------------------------------------------
\tableofcontents
\newpage
\listoffigures
\newpage
\listoftables
% this is the introduction chapter
\newpage
\pagenumbering{arabic}
\chapter*{\centering \vspace{80 mm} Chapter One: Introduction}
\addcontentsline{toc}{chapter}{\numberline{}Chapter One: Introduction}%
\newpage
\justify
\setlength{\parindent}{5 ex}
\section{Introduction}
%write introduction here
\section{Problem Definition}
%write Problem Definition here
\section{Aim and Objectives}
%write Aim and Objectives here
\section{Methodology}
%write Methodology here
\section{Project Scope}
%write Project Scope here
\section{Project Timeline}
%write Project Timeline here
\section{Conclusion}
%write Conclusion here
\end{document}
the table of contentes shows the numbring however the numbers appear only in the first section (introduction). how can I make the numbers appear in the other sections as well ?
for some reason the following package and code affects the numbering of the section (I have no idea why is that happening). when I removed the following code the numbering of the sections appeared in the headings also.
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\fontsize{16}{15}\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\fontsize{14}{15}\bfseries}{\thesection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\fontsize{12}{15}\bfseries}{\thesection}{1em}{}
now I need to find another way to change the font size of the headings. I would appreciate it if any one posts a better way to chanage the font size without using titlesec package.

How to get heading only for the main matter in the report class?

I am writing my thesis in Latex, document class: report. I have got front matter containing of abstract, acknowledgement and so on.
I want to add header only to my main matter which starts with my first chapter:Introduction. I want the header to be the chapter number without the word "chapter" and the chapter title next to it. I also want the page number to appear in the centre on the bottom of the page in all pages of the main matter.
I don't want any header or line in any page of my front matter.
Can you please guide me? Thanks
Here it is the sample code that I am applying.
\documentclass[a4paper,12pt,titlepage]{report}
\usepackage{amsfonts}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{color}
\usepackage{colordvi}
\usepackage{amssymb}
\usepackage{natbib}
\usepackage[nottoc,notlot,notlof]{tocbibind}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{theorem}
\usepackage{lineno}
\usepackage{multirow}
\usepackage [toc,page]{appendix}
\usepackage{framed}
\usepackage{setspace}
\doublespacing
\usepackage[left=1.5in,top=2in,right=1in,bottom=2in]{geometry}
\begin{document}
\title{xxx}
\author{xxx}
\date{xxx}
\maketitle
\thispagestyle{empty}
\renewcommand{\thepage}{\roman{page}}
% here it comes my front matter for example:
\clearpage
\addcontentsline{toc}{chapter}{Abstract}
\chapter*{Abstract}
ABSTRACT CONTENTS
%then:
\clearpage
\cleardoublepage
\pagenumbering{arabic}
% here it starts my main matter:
\chapter{Introduction} %first chapter
\chapter{First Esssay in XXX} %second chapter
\end{document}
You have a number of options to set headers in a document. The most frequently-used package is fancyhdr.
First of all, you need to remove the word Chapter from the regular chapter mark. For this, add
\usepackage{etoolbox}
\makeatletter
%\newcommand{\updatechaptermark}{%
\appto\ps#fancy{%
\patchcmd{\chaptermark}% <cmd>
{\#chapapp\ }{}% <search><replace>
{}{}% <success><failure>
}%}
\makeatother
to your preamble. The above strips out \#chapapp\ (note the space) from \chaptermark as part of the call to \pagestyle{fancy}. That's required as fancyhdr may update \chaptermark upon calling \pagestyle{fancy}.
Second, you need to set the headers/footers. Here's a setting that yields what you're after:
\usepackage{fancyhdr}
\fancyhf{}% Clear header/footer
\fancyhead[C]{\leftmark}% Chapter mark
\fancyfoot[C]{\thepage}% Footer contains the page number
\renewcommand{\headrulewidth}{.4pt}% Header rule width
The above sets the header as \leftmark, which contains the \chaptermark setting (since \chaptermark actually issues \markboth{<leftmark>}{<rightmark>} with an empty <rightmark>).
\documentclass{report}
\usepackage{fancyhdr,lipsum}
\usepackage{etoolbox}
\makeatletter
%\newcommand{\updatechaptermark}{%
\appto\ps#fancy{%
\patchcmd{\chaptermark}% <cmd>
{\#chapapp\ }{}% <search><replace>
{}{}% <success><failure>
}%}
\makeatother
\fancyhf{}% Clear header/footer
\fancyhead[C]{\leftmark}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{.4pt}
\begin{document}
%\frontmatter
\pagenumbering{roman}
\title{xxx}
\author{xxx}
\date{xxx}
\maketitle
\thispagestyle{empty}
% here it comes my front matter for example:
\cleardoublepage
\tableofcontents
\cleardoublepage
\addcontentsline{toc}{chapter}{Abstract}%
\chapter*{Abstract} \lipsum[1]
\cleardoublepage
\pagenumbering{arabic}
\pagestyle{fancy}
\chapter{Introduction} \lipsum[1-50] % first chapter
\chapter{Methodology} \lipsum[1-50] % second chapter
\chapter{Conclusion} \lipsum[1-50] % last chapter
\end{document}
Note that \chapters are set by default using the plain style. If you wish this to be different, you'll have to redefine the plain page style.
You can achieve the same output using a different header/footer package like titleps.

Resources