1

I am using titletoc to customise the ToC. Right now there are three things I cannot solve (I guess, due to the fact that page number is typeset in a fixed-width box):

  1. The titlerule doesn't fill till the page number.
  2. If page number is too large, it exceeds into the right margin.
  3. If the title is too long, it bumps into the page number.

Here is an illustration: enter image description here

I have fixed the first issue with

\makeatletter
\renewcommand{\@pnumwidth}{0pt{}}
\makeatother

but the new problem appears

enter image description here

Full MWE:

\documentclass{book}

\usepackage[showframe]{geometry}
\usepackage{titletoc}
\makeatletter
\renewcommand{\@pnumwidth}{0pt{}}
\makeatother
\titlecontents{chapter}
    [1cm]
    {\vspace{1cm}\filright}
    {\large\sffamily\bfseries\contentslabel[\thecontentslabel.]{1cm}}
    {\hspace{-1cm}}
    {\titlerule*[3pt]{.}\sffamily\bfseries\large\contentspage}

\begin{document}

    \tableofcontents

    \chapter{one}

    Sample text

    \cleardoublepage

    \addtocounter{page}{1000}

    \chapter{two}

    \chapter{a long long long long long long long long long long long long long  title}

\end{document}
2
  • 1
    \renewcommand{\p@numwidth}{0pt} Really? Leaving no space for the page number box?
    – user31729
    Nov 3, 2017 at 19:44
  • @ChristianHupfer David Carlisle suggested this as a solution to my first issue in one question on this site Nov 3, 2017 at 20:19

1 Answer 1

2

This is the best I could obtain with the tools from titletoc. It solves points 2 and 3.

\documentclass{book}

\usepackage[showframe]{geometry}
\usepackage{titletoc}
\contentsmargin{1cm}
\titlecontents{chapter}
    [0.6cm]
    {\vspace{1cm}\filright\large\sffamily\bfseries}
    {\contentslabel[\thecontentslabel.]{1.3em}}
    {\hspace{-1cm}}
    {{\mdseries\hspace{0.4em}\titlerule*[6pt]{.}}\contentspage}

\begin{document}

    \tableofcontents

    \chapter{one}

    Sample text

    \cleardoublepage

    \addtocounter{page}{1000}

    \chapter{two}

    \chapter{a long long long long long long long long long long long long long long title}

\end{document}

enter image description here

5
  • Looks like this works. Can everything be achieved with another package? Nov 4, 2017 at 15:28
  • I guess tocloft can do it, but I don't know it well enough to be sure. As I use titlesec, I prefer to stick to the companion packages titletoc and titleps.
    – Bernard
    Nov 4, 2017 at 15:49
  • to my knowledge, tocloft is less powerfull. And I also use titlesec, so tocloft is the choice Nov 4, 2017 at 15:51
  • @MichaelFraiman: tocloft is less powerful? That's a matter of choice. tocloft and titletoc however should not be used together.
    – user31729
    Nov 4, 2017 at 19:09
  • @ChristianHupfer can this be made with tocloft? Nov 5, 2017 at 16:28

You must log in to answer this question.

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