GeneralMerging Chapter Number and Title in ToC

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Merging Chapter Number and Title in ToC

Post by AleCes »

Hello everybody,

I increased the space between chapter numbers and chapter titles to cope with Roman numbers in ToC, but this workaround doesn't satisfy me anymore. Indeed, a space of 3em necessary for five-digit numbers like XVIII is excessive for one or two-digit numbers like I or II and the result looks very crappy.

What I'd like to do is merging number and title, in other words I need to do away with the fixed numwidth and to treat numbers as if they were parts of the tile.

Minimal example:

Code: Select all

\documentclass[a5paper, openany, 10pt]{book}
\usepackage{bookmark}
\renewcommand{\thechapter}{\Roman{chapter}}
\usepackage{tocloft}
\renewcommand\cftchapaftersnum{.}
\renewcommand\cftchapdotsep{\cftdotsep}
\renewcommand\cftchapnumwidth{3em}
\setlength\cftbeforetoctitleskip{10pt}
\setlength\cftaftertoctitleskip{10pt}
\renewcommand{\cfttoctitlefont}{\hfill\LARGE\bfseries\MakeUppercase}
\renewcommand{\cftaftertoctitle}{\hfill}

\begin{document}
\tableofcontents
\chapter{First Chapter}
\chapter{Second Chapter}
\chapter{Third Chapter}
\chapter{Fourth Chapter}
\chapter{Fifth Chapter}
\chapter{Sixth Chapter}
\chapter{Seventh Chapter}
\chapter{Eighth Chapter}
\chapter{Ninth Chapter}
\chapter{Tenth Chapter}
\chapter{Eleventh Chapter}
\chapter{Twelfth Chapter}
\chapter{Thirteenth Chapter}
\chapter{Fourteenth Chapter}
\chapter{Fifteenth Chapter}
\chapter{Sixteenth Chapter}
\chapter{Seventeenth Chapter}
\chapter{Eighteenth Chapter}
\end{document}
Last edited by AleCes on Sun Feb 09, 2014 4:24 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Merging Chapter Number and Title in ToC

Post by AleCes »

I could go for \renewcommand{\thechapter}{} but that would remove chapter numbers altogether, I'd have to add them manually to chapter titles. Can someone over her think of a less awkward workaround?

Thanks :!:
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Re: Merging Chapter Number and Title

Post by AleCes »

Bump! No hints? :|
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Merging Chapter Number and Title in ToC

Post by AleCes »

Solved thanks to the tip of Jean-François on tug:

Code: Select all

\documentclass{book}
\usepackage{hyperref}
\def\mynumberline #1{#1.\enskip} % I added .\enskip because without these the dots and the space between
% the number and the title would disappear altogether.
\renewcommand\thechapter{\Roman{chapter}}

\begin{document}
\addtocontents{toc}{\let\protect\numberline\protect\mynumberline}
\tableofcontents

\chapter{One}

\chapter{Two}

\setcounter{chapter}{14}
\chapter{Fifteen}

\setcounter{chapter}{17}
\chapter{Eightteen}
\end{document}
Thanks again to Jean-François! ;)
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Merging Chapter Number and Title in ToC

Post by hugovdberg »

I did take a look at your problem but didn't find a good solution. Biggest problem was lack of time to delve into the macro's that construct the toc. There must be a way to redefine these macros so that the title in the toc is prepended with the chapter title, then diable the output of the chapter title, and finally set the space between the (now empty) chapternumber column and the title to zero.
Perhaps setting the \cftchapaftersnumb to the chapternumber would work, but I didn't get that to work. Hope this helps you somewhat.
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
AleCes
Posts: 286
Joined: Sat Nov 13, 2010 9:54 pm

Re: Merging Chapter Number and Title in ToC

Post by AleCes »

Yes, your strategy would mean taking the bull by the horns, instead of devising a workaround like Jean-François'. Too bad you didn't get that to work. Thanks anyway though for devoting your precious time to my issue.
Post Reply