TransWikia.com

Headers of chapters and sections with no change in table of contents

TeX - LaTeX Asked by mwrooo on April 3, 2021

I am using the following fancyhdr package to operate with headers in my paper:

usepackage{fancyhdr}
pagestyle{fancy}
fancyfoot{}
fancyhead[RO,LE]{thepage}
fancyhead[LO]{leftmark}
fancyhead[RE]{rightmark}
renewcommand{headrulewidth}{1pt}
renewcommand{footrulewidth}{0pt}

If now I want to change the header in the chapter (the chapter names are too long) then I write chapter[chapter short name]{full name of chapter} and the same with sections

but such formula gives me "chapter short name" in table of contents. How to change the headers with no changing the original names in table of contents?

2 Answers

You can use chaptermark{...} to set the header.

sectionmark is trickier since it appears on the same page. It is designed to show the first section, and since section calls sectionmark, the default name is the first section. So I created mysection which does not call sectionmark.

documentclass{book}
usepackage{lipsum}

makeatletter
newcommand{mysection}[2][empty]{bgroup
  letsectionmark=@gobble
  edeftemp{#1}%
  ifxemptytemprelax edeftemp{#2}fi
  section[temp]{#2}%
egroup}
makeatother

begin{document}
tableofcontents

chapter[Short title]{Long title}
chaptermark{Short header}

lipsum[1-9]

mysection[Short section title]{Long section title}
sectionmark{Short section header}

lipsum[10-12]

end{document}

Correct answer by John Kormylo on April 3, 2021

The memoir class (a superset of book and report) provides for ToC, header, and regular sectional commands through two optional arguments. For example:

documentclass{memoir}
begin{document}
tableofcontents
chapter[title-in-toc][title-in-header]{main-title}
section[title-in-toc-and-header]{main-title}
subsection{main-title-in-toc-and-header}
subsubsection[title-in-toc][title-in-header]{main-title}
...

Answered by Peter Wilson on April 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP