7

Say I have two titles t1 and t2 for a chapter. I want to show t1 in TOC, and t2 in the first chapter page as well as the in the header.

I use \chapter[t1]{t2} which works for TOC and the first chapter page. However the header shows t1 instead of t2. Is there a way to enforce t2 in the header?

Thanks.

4

With memoir, the syntax for \chapter and \section is extended:

\chapter[toc-title][head-title]{title}

If only one argument is used, the same input is used for the TOC and the header, so you want

\chapter[t1][t2]{t2}

Similarly for \section.


Perhaps you're interested in an easier interface. I define the commands \Chapter and \Section. If called like

\Chapter{Title}

then the behavior is the same as \chapter{title}. But you can call

\Chapter[toc=Title for TOC]{Title}

and the title for headers will be “Title”, while in the TOC you'll get what's stated. The third way of calling it is

\Chapter[toc=Title for TOC,head=Title for head]{Title}

for specifying the three elements independently. Here's a full example.

\documentclass{memoir}
\usepackage{xparse}

\usepackage{kantlipsum} % just for the example

\ExplSyntaxOn
% set up the keys
\keys_define:nn { tmv/titles }
 {
  toc  .tl_set:N = \l_tmv_titles_toc_tl,
  head .tl_set:N = \l_tmv_titles_head_tl,
 }

% user level commands    
\NewDocumentCommand{\Chapter}{ O{} m }
 {
  \tmv_set_titles:nn { #1 } { #2 }
  \tmv_division:VVnN \l_tmv_titles_toc_tl \l_tmv_titles_head_tl { #2 } \chapter
 }

\NewDocumentCommand{\Section}{ O{} m }
 {
  \tmv_set_titles:nn { #1 } { #2 }
  \tmv_division:VVnN \l_tmv_titles_toc_tl \l_tmv_titles_head_tl { #2 } \section
 }

% auxiliary command for setting the keys
\cs_new_protected:Npn \tmv_set_titles:nn #1 #2
 {
  \keys_set:nn { tmv/titles }
   {
    toc = { #2 },
    head = { #2 },
    #1
   }
 }

% the command that calls either \chapter or \section    
\cs_new_protected:Npn \tmv_division:nnnN #1 #2 #3 #4
 {
  #4[#1][#2]{#3}
 }
\cs_generate_variant:Nn \tmv_division:nnnN { VV }
\ExplSyntaxOff

\begin{document}
\frontmatter
\tableofcontents*

\mainmatter
\Chapter{Unique title}
\Section{Unique section title}
\kant

\Chapter[toc=Title for TOC]{Title also for head}
\Section[toc=Title for TOC]{Title also for head}
\kant

\Chapter[toc=Title for TOC 2,head=Title for head]{Title}
\Section[toc=Title for TOC 2,head=Title for head]{Title}
\kant

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.