0

I'm trying to display the page numbers on the left side of the ToC. I used code from the Moving the page number in a table of contents to the left of the titles with tocloft thread and was able to get numbers to display properly on the left of sections.

I haven't been able to adapt the code to also move chapter and part numberings to the left. Any idea how to create a simple solution moving all page numbers to the left?

Here's my current code:

\documentclass[11pt,openany,hidelinks]{book}

\usepackage[utf8]{inputenc}
\usepackage{import}
\usepackage{fullpage}
\usepackage{fontspec}
\usepackage{enotez}
\usepackage{afterpage}
\usepackage{xcolor}
\usepackage{geometry} 
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage{tabularx,graphicx}
\usepackage{imakeidx}
\usepackage{textcomp}
\usepackage{multicol}
\usepackage{multirow}
\usepackage[labelformat=empty]{caption}
\usepackage{array}
\usepackage{makecell}
\usepackage{etoolbox}
\usepackage{float}
\usepackage{hyperref}
\usepackage{changepage}
\urlstyle{rm}
\usepackage{fancyhdr}
\usepackage{url}
\usepackage{xurl}
\graphicspath{ {./images/} }
\indexsetup{othercode=\small}
\makeindex[program=makeindex,columns=2,intoc=false,options={-s index-style.ist}]
\usepackage{enumitem,amssymb}
\usepackage{titlesec}
\usepackage{totcount}
\usepackage{tocloft}

% Font Selection

\setmainfont[
 BoldFont={DMSans-Bold.ttf}, 
 ItalicFont={DMSans-Italic.ttf},
 BoldItalicFont={DMSans-BoldItalic.ttf},
 ]{DMSans-Regular.ttf}

\setmonofont{DMMono-Light.ttf}

% Page Layout

\geometry{
    footskip=35pt}

% Captions

\makeatletter
\renewenvironment{figure}%
  {\renewcommand{\familydefault}{\ttdefault}\selectfont
  \@float{figure}}
  {\end@float}
\makeatother

\captionsetup{justification=raggedright,singlelinecheck=false, font=small,labelfont=tt}
\setlength{\abovecaptionskip}{17pt}
\setlength{\belowcaptionskip}{25pt}

% Chapter Headers

\regtotcounter{chapter}
\titleformat{\chapter}[hang]
  {\raggedright\rmfamily\bfseries\fontsize{62}{56}\selectfont}
  {\huge\rmfamily\mdseries
   % magic number 20pt
   \raisebox{20pt}{\smash{\parbox[t]{3em}{\thechapter\\/\\26}}}}
  {0pt}{}
\titlespacing*{\chapter}{0pt}{50pt}{40pt}[140pt]

% Title Sizes

\titlespacing*{\chapter}{0pt}{0pt}{140pt}

\titleformat{\section}[display]
  {\huge\bfseries}{}{0pt}{\fontsize{22}{28}\selectfont}
\titlespacing*{\section}{0pt}{17pt}{20pt}

\titleformat{\subsection}[display]
  {\huge\bfseries}{}{0pt}{\fontsize{22}{28}\selectfont}
\titlespacing*{\subsection}{0pt}{20pt}{20pt}

% Custom Lists

\newlist{todolist}{itemize}{2}
\setlist[todolist]{label=$\square$}

\title{Solving Product}
\author{Étienne Garbugli}

% Endnotes

\let\footnote=\endnote

\setenotez{
  backref,
  totoc=false,
  counter-format=arabic,
  split=chapter,
  split-title={\Large\chaptername\ <ref> – <title>},
}
\AfterEveryListSplit{\vspace*{-.5\baselineskip}}

\NewSplitTitleTag{title}{\nameref{ch:<split-level-id>}}

\usepackage{nameref}% automatically loaded if you use hyperref

\usepackage{letltxmacro}

\LetLtxMacro\origchapter\chapter
\RenewDocumentCommand\chapter{som}{%
  \IfBooleanTF{#1}
    {% starred chapter, no label then
      \origchapter{#3}%
    }
    {% else add a label
      \IfNoValueTF{#2}
        {\origchapter{#3}}
        {\origchapter[#2]{#3}}%
      \expanded{\noexpand\label{ch:\arabic{chapter}}}%
    }%
}

\DeclareInstance{enotez-list}{endnotes}{paragraph}
 {heading=\section*{#1}, format=\small\ttfamily\raggedright\leftskip3em, number-format=\ttfamily}

% Footer

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\setlength{\headheight}{13.6pt}
\renewcommand{\headrulewidth}{0pt}

\fancypagestyle{mainfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{\leftmark \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

\fancypagestyle{tocfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Table of Contents \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

\fancypagestyle{preffoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Preface \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

% Redefine the plain page style

\fancypagestyle{plain}{%
\fancyhf{}%
\fancyfoot[RO]{\footnotesize\ttfamily{\thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage}}
}

% Redefine Part page style

\fancypagestyle{s1foot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Stage 1: Idea \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

\fancypagestyle{s2foot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Stage 2: Startup \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

\fancypagestyle{s3foot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Stage 3: Growth \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

\fancypagestyle{s4foot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Stage 4: Expansion \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

\fancypagestyle{s5foot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Stage 5: Maturity \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

% Redefine Backmatter page style

\fancypagestyle{bbfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Building Blocks \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

\fancypagestyle{appfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Appendices \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

\fancypagestyle{notfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Notes \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

\fancypagestyle{indfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{Index \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}}

\fancypagestyle{endfoot}{
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{\thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage}}}

% List Styles

\setlist[enumerate]{itemsep=2pt,topsep=12pt}

% Indentation

\newenvironment{genind}{\begin{adjustwidth}{12mm}{}}{\end{adjustwidth}}

\newenvironment{quotlarind}{\begin{adjustwidth}{3pt}{60pt}}{\end{adjustwidth}}
\newenvironment{quotmedind}{\begin{adjustwidth}{3pt}{80pt}}{\end{adjustwidth}}

% Table of Contents Config

\newcount\cnta
\cftsetpnumwidth{0pt}
\renewcommand\cftsecpagefont {\ttfamily\global\cnta}
\renewcommand\cftsecafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\the\cnta}}%
}
\renewcommand{\cftpartfont}{\ttfamily\large} 
\renewcommand{\cftchapfont}{\rmfamily\large\bfseries} \renewcommand{\cftdot}{}
\renewcommand{\contentsname}{Table of Contents}
\setcounter{tocdepth}{1}
\setcounter{secnumdepth}{0}
\newlength\mylength
\renewcommand{\cftchappresnum}{Chapter }
\renewcommand{\cftchapaftersnum}{ – } 
\newlength{\tocl}
\settowidth{\tocl}{\bfseries\cftchappresnum\cftchapaftersnum}
\addtolength{\cftchapnumwidth}{\tocl}

\renewcommand\cftchapafterpnum{\vskip7pt}
\renewcommand\cftpartafterpnum{\vskip12pt}
\setlength{\cftsecindent}{4em}

\renewcommand{\cftchappagefont}{\ttfamily}   
\renewcommand{\cftpartpagefont}{\ttfamily} 

\newcounter{oldtocdepth}

\newcommand{\hidefromtoc}{%
  \setcounter{oldtocdepth}{\value{tocdepth}}%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-10}}%
}

\newcommand{\unhidefromtoc}{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{\value{oldtocdepth}}}%
}

\begin{document}

% Table of Contents

\tableofcontents{}

\addcontentsline{toc}{part}{Inception}

\chapter{Chapter 1}
\Section{Section A}
\Section{Section B}
\Section{Section C}

\addcontentsline{toc}{part}{Stage 1}

\chapter{Chapter 1}
\Section{Section A}
\Section{Section B}
\Section{Section C}

\addcontentsline{toc}{part}{Retrospective}

\chapter{Chapter 1}
\Section{Section A}
\Section{Section B}
\Section{Section C}

\end{document}

Right now it looks like this:

Table of Content – Mixed numbering

Note that I'm also using the following code to add 'Chapter' and a hyphen to chapter names:

\newlength\mylength
\renewcommand{\cftchappresnum}{Chapter }
\renewcommand{\cftchapaftersnum}{ – } 
\newlength{\tocl}
\settowidth{\tocl}{\bfseries\cftchappresnum\cftchapaftersnum}
\addtolength{\cftchapnumwidth}{\tocl}

Results aren't perfect.

  • 1
    Welcome to TeX.SX! I have understood your question, but it would have made a better question if you omit obviously unnecessary packages and codes to your table of contents. For instance, url/xurl packages and endnotes are unrelated to this question. Plz have a glance at how to build MWE. Have a nice day! – domperor Aug 3 at 7:24
  • 1
    Thanks for the feedback. I appreciate that. – egarbugli Aug 3 at 19:20
2

U have used the hack of renewing \cftsecpagefont and \cftsecafterpnum. The same works in the chap and the part as follows:

\renewcommand{\cftchappagefont}{\ttfamily\global\cnta}
\renewcommand\cftchapafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\the\cnta}}%
}
\renewcommand{\cftpartpagefont}{\ttfamily\global\cnta}
\renewcommand\cftpartafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\the\cnta}}%
}

The following is a smaller working example that simplified your document:

\documentclass{book}
\usepackage{tocloft}

\newcount\cnta
\cftsetpnumwidth{0pt}
\renewcommand\cftsecpagefont {\ttfamily\global\cnta}
\renewcommand\cftsecafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\the\cnta}}%
}
\renewcommand{\cftchappagefont}{\ttfamily\global\cnta}
\renewcommand\cftchapafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\the\cnta}}%
\vskip7pt
}
\renewcommand{\cftpartpagefont}{\ttfamily\global\cnta}
\renewcommand\cftpartafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\the\cnta}}%
\vskip14pt
}

\renewcommand{\cftdot}{}
\setcounter{tocdepth}{1}
\setcounter{secnumdepth}{0}
\renewcommand{\cftchappresnum}{Chapter }
\renewcommand{\cftchapaftersnum}{ – }
\newlength{\tocl}
\settowidth{\tocl}{\bfseries\cftchappresnum\cftchapaftersnum}
\addtolength{\cftchapnumwidth}{\tocl}

\renewcommand{\cftpartfont}{\ttfamily\large} 
\renewcommand{\cftchapfont}{\rmfamily\large\bfseries}

\setlength{\cftpartindent}{4em}
\setlength{\cftchapindent}{4em}
\setlength{\cftsecindent}{4em}

\begin{document}

\tableofcontents{}

\addcontentsline{toc}{part}{Inception}

\chapter{Introduction}
\section{Hockey}
\section{Why}

\addcontentsline{toc}{part}{Stage 1}

\chapter{Isolating}
\section{How}
\section{Visualising}
\section{How}

\addcontentsline{toc}{part}{Retrospective}

\chapter{Asking}
\section{Is this}
\section{Finding}
\section{Rubik}

\end{document}

Result: result


Edit: as for size modification of the page numbers

You can add the size command into \cftpartafterpnum, \cftchapafterpnum, and \cftsecafterpnum.

e.g. inserting \large in \cftchapafterpnum

\renewcommand\cftchapafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\large\the\cnta}}%
}
| improve this answer | |
  • Works great! Any way to make the page numbers the same size as the items they're referring to (parts vs sections vs sections)? – egarbugli Aug 3 at 19:20
  • I am happy to hear that. I have edited my answer for the modification of the sizes of page numbers. – domperor Aug 5 at 1:19
  • 1
    Perfect. It worked flawlessly. Thanks so much for the help. :-) – egarbugli Aug 5 at 8:51

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.