2

I have unnumbered chapter titles (using \chapter*) but I still need an optional argument for a shorter version of the title, for headers. When I write \chapter*[Short title]{Long title} it fails. Do I need to redefine everything or is there some way to define the short title with some other command?

Here is a minimal example with the standard bookclass:

\documentclass{book}
\begin{document}
\chapter*[A short version of the title]{A very very very very very very 
very very very long title that doesn't fit in my header}
Bla bla.
\end{document}

that gives

enter image description here

2
  • 1
    What document class are you using? (preferrably, add a minimal example, if possible) Feb 13, 2020 at 18:31
  • Just added a minimal example with the standard book class.
    – yannis
    Feb 13, 2020 at 19:49

1 Answer 1

3

The following redefines \chapter to accommodate for the use of an optional star * or optional. In the case of \chapter*, the optional argument is used to set the header detail:

enter image description here

\documentclass{book}

\usepackage{xparse,lipsum}

\makeatletter
\let\oldchapter\chapter
\RenewDocumentCommand{\chapter}{s o m}{% \chapter*[<opt>]{<man>}
  \IfBooleanTF{#1}
    % \chapter*
    {\IfValueTF{#2}
      % \chapter*[..]{...}
      {\oldchapter*{#3}%
       %\addcontentsline{toc}{chapter}{\protect\numberline{}#3}% Add regular title to ToC
       %\addtocontents{lof}{\protect\addvspace{10\p@}}% Space between chapters in LoF
       %\addtocontents{lot}{\protect\addvspace{10\p@}}% Space between chapters in LoT
       \markboth{#2}{}% Set marks based on optional argument
      }
      % \chapter*{...}
      {\oldchapter*{#3}}}
    % \chapter
    {\IfValueTF{#2}
      % \chapter[..]{...}
      {\oldchapter[#2]{#3}}
      % \chapter{...}
      {\oldchapter{#3}}}%
}
\makeatother

\begin{document}

\chapter*
  [A short version of the title]
  {A very very very very very very very very very long title that doesn't fit in my header}
\sloppy\lipsum[1-50]

\end{document}

Some additional detail have been commented out if, for example, you wish to add content to the ToC. Formatting of the new chapter mark for \chapter*[<header>]{<main title>} has been left out (default used to be \MakeUppercase), but you can add that:

\markboth{\MakeUppercase{#2}}{}
1
  • Wow, thanks! This xparse package seems astonishing. You manage to redefine \chapter and to keep the formatting I had, unchanged, that's great.
    – yannis
    Feb 13, 2020 at 20:32

You must log in to answer this question.

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