0

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?

1
  • You can use load titlesec with the toctitles option for that (possibly you might have to load titleps in the place of fanyhdr for headers and footers – not tested).
    – Bernard
    Feb 26, 2021 at 11:01

2 Answers 2

0

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
  \let\sectionmark=\@gobble
  \edef\temp{#1}%
  \ifx\empty\temp\relax \edef\temp{#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}
3
  • Okay, that's it. \chaptermark (similarly \sectionmark) does not change the title in table of contents. Thank You very much!
    – mwrooo
    Feb 26, 2021 at 14:22
  • Update: okay it works almost: the long section title is on the page where the section starts, despite sectionmark function...
    – mwrooo
    Feb 26, 2021 at 14:27
  • Another solution is to run \sectionmark before \section. If \section causes a pagebreak, stick a \par\pagebreak or \needspace in front. Feb 27, 2021 at 2:41
0

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}
...

You must log in to answer this question.

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