GeneralHow to remove the last numbered section title in header?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to remove the last numbered section title in header?

Post by Cham »

I'm writing a book with several chapters and sections, and I'm using the fancyhdr package to customize the header. Each chapter ends with a special unumbered part for exercices and answers. That exercices part is shown in the ToC as an unumbered chapter. The MWE code below shows this. Everything works fine, but I noticed a glitch yesterday : in the exercices and answers part, the header is showing the last section title (see the last page of the compiled code). This shouldn't be the case. I would like to change it for the current unumbered section title, i.e. "Answers to problems" (without numbering). So how to do that ?

Code: Select all

\documentclass[11pt,twoside]{book}
\usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}
\fancyhead[LE]{\itshape\small\MakeUppercase{\leftmark}}
\fancyhead[RE]{}
\fancyhead[CO,CE]{}
\fancyhead[LO]{}
\fancyhead[RO]{\itshape\small\MakeUppercase{\rightmark}}
\fancyfoot[CE,CO]{\textsc{Student class title}}
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[RE,LO]{}
\setlength{\headheight}{14pt}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

\begin{document}
\pagestyle{plain}
\setcounter{tocdepth}{3}
\tableofcontents
\pagestyle{fancy}

\chapter{First chapter title}

Blabla!

\section{A section title}

Blabla bla!

\newpage

More blabla bla!

\newpage
\section{The last section title}

\newpage
\chapter*{Some problems for the students} % <--- Shown as an unumbered chapter in the ToC
\addcontentsline{toc}{chapter}{Some problems for the students}

Blabla

\newpage
More blablabla!

\newpage
\section*{Answers to problems} % <--- This title should be shown in the header instead of the last numbered section
\addcontentsline{toc}{section}{Answers to problems}
Blablabla
\end{document}
I suspect that I should simply add one renewcommand after the lines \chapter*{Some problems for the students} and \section*{Answers to problems} to locally change the current section title, but I don't see what command exactly. Any suggestion ?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to remove the last numbered section title in header?

Post by Cham »

Oooh! I may already have found the solution ! :lol:

Adding this command appears to solve my issue :
\renewcommand{\rightmark}{New section title in header!}

Is that the proper solution?

EDIT: Hmm, this is a partial solution only. As soon as I add a new chapter and new sections, the new sections doesn't have their title displayed in the header. Houston, we have a problem!
Last edited by Cham on Mon Jun 25, 2018 3:19 pm, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

How to remove the last numbered section title in header?

Post by Stefan Kottwitz »

The proper way would be \markright, after \clearpage:

Code: Select all

\clearpage
\markright{Answers to problems}
\section*{Answers to problems}
Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

How to remove the last numbered section title in header?

Post by Cham »

Whoa ! Thanks Stefan. It appears to work great! :D

I'll check the topic "solved" in a few minutes, after I'm sure my problem is fully solved. :)
Post Reply