2

I have document like this:

\documentclass{book}
\renewcommand\thechapter{\Roman{chapter}} 
\begin{document}
\chapter{Some title}
\chapter{Some other title}
\chapter{One more title}
\tableofcontents
\end{document}

It produces table of contents like: what I have

What i need is no space between chapter number ant its caption, like: what I need

tocloft allows to use \cftchapnumwidth command , but it is "static", I want chapnumwidth to be adjusted to each number.

Thank you

  • Welcome to TeX.SX! Your request would generate ToCs being difficult to read. – user31729 Nov 27 '14 at 6:38
2

Even tocloft still uses the traditional setting of the ToC entry numbers inside a box (of width \cftZnumwidth, where Z is the sectional unit). But, we can patch \l@chapter to momentarily adjust \numberline - the macro causing the problems. The patching is supplied by etoolbox.

Below I've done so, even though the readability of the ToC now completely suffers from it:

enter image description here

\documentclass{book}
\usepackage{tocloft,etoolbox}
\makeatletter
\patchcmd{\l@chapter}% <cmd>
  {\leavevmode}% <search>
  {\leavevmode%
   \renewcommand{\numberline}[1]{\hbox{\@cftbsnum ##1\@cftasnum}\@cftasnumb}}% <replace>
  {}{}% <success><failure>
\makeatother
\renewcommand\thechapter{\Roman{chapter}} 
\begin{document}

\tableofcontents

\chapter{Some title}
\section{A section}

\chapter{Some other title}

\chapter{One more title}

\end{document}

For a fixed space after the chapter numeral, adjust \cftchappresnum to something like ~.

1
\documentclass{book}

\def\numberline#1{#1}
\renewcommand\thechapter{\Roman{chapter}} 
\begin{document}
\chapter{Some title}
\chapter{Some other title}
\chapter{One more title}
\tableofcontents
\end{document}

enter image description here

And if you have sections with the default TOC entry then use:

\documentclass{book}

\makeatletter
\renewcommand*\l@chapter[2]{%
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \begingroup
      \def\numberline##1{##1}
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
      \penalty\@highpenalty
    \endgroup}
\makeatother
\renewcommand\thechapter{\Roman{chapter}} 
\begin{document}
\chapter{Some title}
\section{foo}
\chapter{Some other title}
\chapter{One more title}
\tableofcontents
\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.