1

I'm formatting the final draft of my thesis and have noticed a problem with the chapter and section titles as they appear in the headers.

At the moment I'm using fancyhdr to get the chapter and section titles on alternate pages in the headers. For separate reasons I don't want my introduction chapter and conclusion chapter to be numbered, and I don't want the concluding section of each chapter to be numbered. To achieve this, I've used the \chapter* and \section* commands. However, this has had three unwanted results regarding the chapter/section titles which appear in some of the headers:

  1. 'Contents' appears as the chapter title in the header for the introduction:

enter image description here

But I would like it to say 'Introduction'.

  1. The previous section name appears as the section title in the header for the concluding section of the chapters:

enter image description here

But I would like it to say 'Conclusion'.

  1. The previous chapter title appears as the chapter title in the header for the conclusion chapter:

enter image description here

Again, I'd like this to say 'Conclusion'.

Here's a MWE:

\documentclass[12pt, twoside]{report}

\usepackage[explicit]{titlesec} %adjust titles
\usepackage{lipsum} %random text

%%%%%%%%Chapter and section titles in headers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{} %clears header
\fancyhead[CE]{\nouppercase{\textit{\leftmark}}} %puts chapter title on even page in lower-case italics
\fancyhead[CO]{\nouppercase{\textit{\rightmark}}} %puts section title on odd page in lower-case italics
\renewcommand{\headrulewidth}{0pt} %gets rid of line
\renewcommand{\chaptermark}[1]{\markboth{#1}{}} %gets rid of chapter number
\renewcommand{\sectionmark}[1]{\markright{#1}} %gets rid of section number
%%%%%%%%%

\titleformat{\chapter}[display]{\LARGE\bfseries\centering}{\thechapter}{10pt}{#1}
\titleformat{\section}{\normalfont\fontsize{20}{20}\centering}{\thesection}{1em}{\MakeUppercase{#1}}
\titleformat{\subsection}{\normalfont\centering}{\thesubsection}{1em}{\textit{{#1}}}

\usepackage{subfiles} %allows multi-file projects

\setcounter{tocdepth}{1} %removes subsubsections from toc

%%%%%%%%%removes dots from toc
\makeatletter 
\renewcommand{\@dotsep}{10000} 
\makeatother
%%%%%%%%%

\begin{document}

\tableofcontents

\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}

\renewcommand{\thesection}{\arabic{section}}

\section{An Introductory Section}

\lipsum
\lipsum[1]

\section{Another Introductory Section}

\lipsum

\chapter{A Chapter}
\renewcommand{\thesection}{\thechapter.\arabic{section}}


\lipsum[2-3]

\section{A Section}

\lipsum[4-8]

\section*{Conclusion}

\lipsum[8-9]

\chapter{Another Chapter}
\renewcommand{\thesection}{\thechapter.\arabic{section}}


\lipsum[1-2]

\chapter*{Conclusion}
\addcontentsline{toc}{chapter}{Conclusion}

\lipsum

\end{document}

I'm aware that similar questions have been asked (e.g. Unnumbered chapter in toc and heading) but they seem to be about KOMA-Script. Given that this is a final draft, if it's possible to do this using fancyhdr and without having to change loads of things that'd be ideal. Thanks!

1 Answer 1

2

I propose this simpler code, with the pagestyles option of titlesec, which defines the \chaptermark command, and for unumbered sections,the \pretitlemark (to be used in \titleformat and before \section*) :

\documentclass[12pt, twoside]{report}

\usepackage[explicit, pagestyles]{titlesec} %adjust titles
\usepackage{lipsum} %random text

\titleformat{\chapter}[display]{\LARGE\bfseries\filcenter}{\thechapter}{10pt}{#1}
\titleformat{name=\chapter, numberless}[display]{\LARGE\bfseries\filcenter}{}{10pt}{\chaptermark{#1}\addcontentsline{toc}{chapter}{#1}#1}

\titleformat{\section}{\normalfont\fontsize{20}{20}\filcenter}{\thesection}{1em}{\MakeUppercase{#1}}
\titleformat{name=\section, numberless}{\normalfont\fontsize{20}{20}\filcenter}{}{0em}{\pretitlemark{section}{#1}\MakeUppercase{#1}}
\renewcommand{\thesection}{\ifthechapter{\thechapter.}{}\arabic{section}}

\titleformat{\subsection}{\normalfont\filcenter}{\thesubsection}{1em}{\textit{{#1}}}

\newpagestyle{myps}{%
\sethead[][\itshape\chaptertitle][]{}{\itshape\sectiontitle}{}
\setfoot{}{\thepage}{}
}
%%%%%%%%%Chapter and section titles in headers
\pagestyle{myps}
\usepackage{subfiles} %allows multi-file projects

\setcounter{tocdepth}{1} %removes subsubsections from toc

%%%%%%%%%removes dots from toc
\makeatletter
\renewcommand{\@dotsep}{10000}
\makeatother
%%%%%%%%%

\begin{document}

\tableofcontents

\chapter*{Introduction}

\section{An Introductory Section}

\lipsum
\lipsum[1]

\section{Another Introductory Section}

\lipsum

\chapter{A Chapter}

\lipsum[2-5]

\section{A Section}

\lipsum[6-8]

\pretitlemark{section}{Conclusion}
\section*{Conclusion}

\lipsum[9-15]

\chapter{Another Chapter}

\lipsum[13-16]

\chapter*{Conclusion}

\lipsum[17-20]

\end{document} 
7
  • Thanks so much for this! The chapter and section titles now appear exactly as I want them to in the headers, but the unnumbered sections and chapters are now appearing in the table of contents. Is there any way to stop this from happening whilst keeping everything else as it is? Sep 13, 2020 at 16:37
  • I'll have to think about this. I thought you also wanted them in the table of contents.
    – Bernard
    Sep 13, 2020 at 17:15
  • Sorry if I was unclear about this and thanks for your help! Sep 13, 2020 at 17:31
  • 1
    @JamesSkinner: You just have to remove \addcontentsline{toc}{section}{#1} in \titleformat{name=\section, numberless}{...}. I corrected the code (which now still adds unnumbered chapters in the toc, but not unnumbered sections)`.
    – Bernard
    Sep 13, 2020 at 18:41
  • 1
    That's not too much at al: we're here to help. You can try placing \titleformat{name=\chapter, numberless}{…} just after \tableofcontents instead of the preamble.
    – Bernard
    Sep 14, 2020 at 8:51

You must log in to answer this question.

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