0

I am trying to produce a TOC that runs ragged right. I want the distance between all titles (parts, chapters, sections) and page numbers to be 3 times the distance that's between the part/chapter/section number and the title. No dots or anything.

I see how to set the indentation from the right by changing 4em in the MWE below, but I do not know how to calculate the appropriate number.

I would also like to align the front matter/intro title with the part number below it and then both of those aligned with the chapter titles instead of everything flush left.

\documentclass{book}

\usepackage[titles]{tocloft}

\renewcommand{\cftdotsep}{\cftnodots}
\renewcommand{\cftpartafterpnum}{\hspace*{4em}}
\renewcommand{\cftchapafterpnum}{\hspace*{4em}}
\renewcommand{\cftsecafterpnum}{\hspace*{4em}}
\renewcommand{\cftpnumalign}{l}

\begin{document}

\frontmatter
\tableofcontents
\chapter{Introduction}
\part{This is Part One}
\mainmatter
\chapter{First Chapter}
\section{First Section}

\end{document}

So the I from Introduction should be aligned with the I which is the part number, and these both should be indented to align with the F from First Chapter.

Suggestions?

0

Try this:

% tocprob.tex  SE 552100

\documentclass{book}
\usepackage[titles]{tocloft}

%%%%%% your code
\renewcommand{\cftdotsep}{\cftnodots}
\renewcommand{\cftpartafterpnum}{\hspace*{4em}}
\renewcommand{\cftchapafterpnum}{\hspace*{4em}}
\renewcommand{\cftsecafterpnum}{\hspace*{4em}}
\renewcommand{\cftpnumalign}{l}

%%%%%%%%% my code
\newlength{\mylength}
\setlength{\mylength}{10em}
\renewcommand{\cftpartafterpnum}{\cftparfillskip}
\renewcommand{\cftchapafterpnum}{\cftparfillskip}
\renewcommand{\cftsecafterpnum}{\cftparfillskip}
\renewcommand{\cftpartpagefont}{\hspace{\mylength}\large\bfseries}
\renewcommand{\cftchappagefont}{\hspace{\mylength}\bfseries}
\renewcommand{\cftsecpagefont}{\hspace{\mylength}\normalfont}
\renewcommand{\cftpartleader}{}
\renewcommand{\cftchapleader}{}
\renewcommand{\cftsecleader}{}

\setlength{\cftpartindent}{1.2em} % align part numbers with chapter titles 

\begin{document}

\frontmatter
\setlength{\cftchapindent}{3em} % indent unnumbered chapters
\tableofcontents
\chapter{Introduction}
\part{This is Part One}
\addtocontents{toc}{\setlength{\cftchapindent}{2em}} % regular chapter indent
\mainmatter
\chapter{First Chapter}
\section{First Section}

\end{document}

I used a spacing of \mylength between the end of the titles and the page numbers. The actual space between a number and the title text is specified by the \cftXnumwidth tocloft macros which by default are different for each X (> texdoc tocloft). You could use a multiple of these for each division level but I'm not sure that it would enhance the viewer's impression.

I have edited my original answer to try and cater for the questioner's comments.

| improve this answer | |
  • When I change 4em I do not see any effect. Also, how can I indent 'Introduction'? – E2R0NS Jul 5 at 5:36
  • @E2R0NS I have edited my original answer to cater for your comment. I have shown how to indent the Introduction. If you see ne effect from changing 4em I have no idea what you might have done in your code. I introduced a length mylength to be used for adjusting horizontal spacing. It is entirely up to you how you organise the spacing of your output. --- GOM – Peter Wilson Jul 5 at 18:29
  • The alignment worked after some adjustment. The title and page number distance is still not responding but I accomplished what I wanted for the most part by using spaces such as \quad as a leader: \renewcommand{\cftpartleader}{\quad} – E2R0NS Jul 6 at 0:18

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.