[Tex/LaTex] Adjust space between chapter number and caption in TOC

spacingtable of contentstocloft

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

Best Answer

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 ~.