1

Usually, when I want to reduce the size of some of my titles in the headers, I use [a short title in brackets]. But, this time, I'd like to use long titles in the TOC, but the headers have to be short. How could I achieve this? This is my MWE:

\documentclass[hidelinks,12pt,twoside,openright,a4paper]{book}
\setlength{\headheight}{14.49998pt}
\addtolength{\topmargin}{-2.49998pt}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{setspace}
 \linespread{1.1}

\usepackage[left=5.5cm,right=5.5cm,top=6.5cm,bottom=6.5cm]{geometry}

\usepackage{lipsum}

\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathptmx}

\usepackage{titlesec}
\usepackage{titling}
\titleformat*{\section}{\normalsize\itshape}
\titleformat*{\subsection}{\normalsize\itshape}
\titleformat*{\subsubsection}{\normalsize\itshape}


\usepackage{tocloft}
\setlength{\cftbeforechapskip}{3pt}%espace entre chapitres
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} % for chapters


\usepackage{hyperref}
\usepackage[numberedbib,nosectionbib]{apacite}
\usepackage[makeindex]{imakeidx}
\makeindex[name=npr, title=Index des noms] 
\makeindex[name=mat, title=Index des matières]

\usepackage{fancyhdr}
\pagestyle{fancy}
% We don't want chapter and section numbers
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\headrulewidth}{0pt}
\fancyhf{} % sets both header and footer to nothing
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[CE]{\textit{A name}} % even pages: chapter title
\fancyhead[CO]{\textit\leftmark} % odd pages: book title


%%%%%%%%%%%%Pas de N° de chapitres%%%%%%%%%%%%%%%%%%%%

\usepackage{titlesec}
\titleformat{\chapter}[display]%
    {\centering\Large\bfseries}% format of chapter
    {\large\normalfont\MakeUppercase{\chaptertitlename}\enskip\thechapter}% format of the label
    {.5\baselineskip}{} % space between the two
\titlespacing*{\chapter}{0pt}{25pt}{35pt} % spaces around \chapter{}, {left}{before}{after}
 
%\titleformat{\chapter}[display]
  %{\normalfont\bfseries}{}{0pt}{\Huge}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%épigraphe%%%%%%%%%%%%
\makeatletter
\renewcommand{\@chapapp}{}% Not necessary...
\newenvironment{chapquote}[2][2em]
  {\setlength{\@tempdima}{#1}%
   \def\chapquote@author{#2}%
   \parshape 1 \@tempdima \dimexpr\textwidth-2\@tempdima\relax%
   \itshape}
  {\par\normalfont\hfill---\ 
 \chapquote@author\hspace{\@tempdima}\par\bigskip\par\bigskip}
\makeatother

%%%%%%%%%%%%%Numérotation en chiffres arabes%%%%%%%%%%%%%%%%%%%
\makeatletter
\renewcommand\frontmatter{%
  \cleardoublepage
  \@mainmatterfalse
  %\pagenumbering{roman}% Don't reset
}
\renewcommand\mainmatter{%
  \cleardoublepage
  \@mainmattertrue
  %\pagenumbering{arabic}% Don't reset
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

\begin{document}
\title{A title}
\author{A name}
\date{}
\maketitle


\renewcommand{\contentsname}{Sommaire}
\tableofcontents
\frontmatter

\mainmatter


\chapter[A chapter whose the title is short]{A chapter which has a very very very long title as you can see}
\lipsum
\chapter{A section which has also a very very very long title as you can see}
\lipsum


\backmatter
\chapter{Conclusion}

\end{document}
5
  • 1
    The way to go, since you use titlesec, is to load it with option [toctitles]. The optional argument of chapter will be used only in the headers (see §3.7 of the documentation).
    – Bernard
    Commented Aug 12, 2021 at 12:41
  • I tried this, but it does not work as you say: \usepackage[toctitles]{titlesec}. Is this code right?
    – domi
    Commented Aug 12, 2021 at 12:51
  • That is OK. I never tried this option, but perhaps it is linked to your using tocloft for the formatting of your table of contents. Anyway, titlesec has a companion package for that: titletoc. You should try to see first if it works with the default formatting. Also, another question: did you compile at least twice with this option?
    – Bernard
    Commented Aug 12, 2021 at 12:57
  • I removed tocloft, but it does not change anything. Even using \usepackage{titletoc}, it does not work at all.
    – domi
    Commented Aug 12, 2021 at 14:02
  • toctitles optoin seems to work for sections, not chapters - see workaround at tex.stackexchange.com/questions/498592/… . Alternatively, use \chaptermark: \chapter{VERY VERY VERY VERY LONG TITLE} \chaptermark{SHORT TITLE} - see tex.stackexchange.com/questions/216144/…
    – Cicada
    Commented Aug 13, 2021 at 12:36

1 Answer 1

2

The memoir class (a superset of book, report, ...) has two optional arguments for division titles. For example:

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

where toc-title is put in the ToC, head-title is put in the page headers, and title is the section's title in the body of the document.

All the division macros from \chapter through \subparagraph have the same capabilities.

2
  • It works. Does the memoir class offer the same capabilities of the book class? With this solution, I can't use tocloft anymore.
    – domi
    Commented Aug 14, 2021 at 9:23
  • The memoir class includes, and extends, the capabilities of the tocloft package, albeit with some minor changes in the macro names. For example \cftsectiondotsep instead of cftsecdotsep. In general division names like \section, or captions, are spelled out in full instead of shortened. Like cftfigurefont instead of \cftfigfont. Commented Aug 15, 2021 at 18:12

You must log in to answer this question.

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