LaTeX forum ⇒ GeneralHow to remove the last numbered section title in header? Topic is solved

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

How to remove the last numbered section title in header?

Postby Cham » Mon Jun 25, 2018 2:47 pm

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 ?

  1. \documentclass[11pt,twoside]{book}
  2. \usepackage[total={6.25in,10in},left=1.25in,top=0.5in,includehead,includefoot]{geometry}
  3. \usepackage{fancyhdr}
  4. \fancyhf{}
  5. \pagestyle{fancy}
  6. \fancyhead[LE]{\itshape\small\MakeUppercase{\leftmark}}
  7. \fancyhead[RE]{}
  8. \fancyhead[CO,CE]{}
  9. \fancyhead[LO]{}
  10. \fancyhead[RO]{\itshape\small\MakeUppercase{\rightmark}}
  11. \fancyfoot[CE,CO]{\textsc{Student class title}}
  12. \fancyfoot[LE,RO]{\thepage}
  13. \fancyfoot[RE,LO]{}
  14. \setlength{\headheight}{14pt}
  15. \renewcommand{\headrulewidth}{0.4pt}
  16. \renewcommand{\footrulewidth}{0.4pt}
  17.  
  18. \begin{document}
  19. \pagestyle{plain}
  20. \setcounter{tocdepth}{3}
  21. \tableofcontents
  22. \pagestyle{fancy}
  23.  
  24. \chapter{First chapter title}
  25.  
  26. Blabla!
  27.  
  28. \section{A section title}
  29.  
  30. Blabla bla!
  31.  
  32. \newpage
  33.  
  34. More blabla bla!
  35.  
  36. \newpage
  37. \section{The last section title}
  38.  
  39. \newpage
  40. \chapter*{Some problems for the students} % <--- Shown as an unumbered chapter in the ToC
  41. \addcontentsline{toc}{chapter}{Some problems for the students}
  42.  
  43. Blabla
  44.  
  45. \newpage
  46. More blablabla!
  47.  
  48. \newpage
  49. \section*{Answers to problems} % <--- This title should be shown in the header instead of the last numbered section
  50. \addcontentsline{toc}{section}{Answers to problems}
  51. Blablabla
  52. \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 ?

User avatar
Cham
Posts: 885
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Jun 25, 2018 3:15 pm

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: 8946
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Mon Jun 25, 2018 3:19 pm

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

  1. \clearpage
  2. \markright{Answers to problems}
  3. \section*{Answers to problems}


Stefan
Site admin

User avatar
Cham
Posts: 885
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Mon Jun 25, 2018 3:23 pm

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. :)


Return to “General”

Who is online

Users browsing this forum: No registered users and 7 guests