TransWikia.com

Displaying all page numbers in ToC on the left-hand side?

TeX - LaTeX Asked on February 19, 2021

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]
  {raggedrightrmfamilybfseriesfontsize{62}{56}selectfont}
  {hugermfamilymdseries
   % 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]
  {hugebfseries}{}{0pt}{fontsize{22}{28}selectfont}
titlespacing*{section}{0pt}{17pt}{20pt}

titleformat{subsection}[display]
  {hugebfseries}{}{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

letfootnote=endnote

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

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

usepackage{nameref}% automatically loaded if you use hyperref

usepackage{letltxmacro}

LetLtxMacroorigchapterchapter
RenewDocumentCommandchapter{som}{%
  IfBooleanTF{#1}
    {% starred chapter, no label then
      origchapter{#3}%
    }
    {% else add a label
      IfNoValueTF{#2}
        {origchapter{#3}}
        {origchapter[#2]{#3}}%
      expanded{noexpandlabel{ch:arabic{chapter}}}%
    }%
}

DeclareInstance{enotez-list}{endnotes}{paragraph}
 {heading=section*{#1}, format=smallttfamilyraggedrightleftskip3em, number-format=ttfamily}

% Footer

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

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

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

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

% Redefine the plain page style

fancypagestyle{plain}{%
fancyhf{}%
fancyfoot[RO]{footnotesizettfamily{thepage}}
fancyfoot[LE]{footnotesizettfamily{thepage}}
}

% Redefine Part page style

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

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

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

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

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

% Redefine Backmatter page style

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

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

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

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

fancypagestyle{endfoot}{
fancyhf{}
fancyfoot[RO]{footnotesizettfamily{thepage}}
fancyfoot[LE]{footnotesizettfamily{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

newcountcnta
cftsetpnumwidth{0pt}
renewcommandcftsecpagefont {ttfamilyglobalcnta}
renewcommandcftsecafterpnum {%
  makebox[0pt][l]%
     {kern-dimexprlinewidthrelaxmakebox[2em][l]{thecnta}}%
}
renewcommand{cftpartfont}{ttfamilylarge} 
renewcommand{cftchapfont}{rmfamilylargebfseries} renewcommand{cftdot}{}
renewcommand{contentsname}{Table of Contents}
setcounter{tocdepth}{1}
setcounter{secnumdepth}{0}
newlengthmylength
renewcommand{cftchappresnum}{Chapter }
renewcommand{cftchapaftersnum}{ – } 
newlength{tocl}
settowidth{tocl}{bfseriescftchappresnumcftchapaftersnum}
addtolength{cftchapnumwidth}{tocl}

renewcommandcftchapafterpnum{vskip7pt}
renewcommandcftpartafterpnum{vskip12pt}
setlength{cftsecindent}{4em}

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

newcounter{oldtocdepth}

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

newcommand{unhidefromtoc}{%
  addtocontents{toc}{protectsetcounter{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:

newlengthmylength
renewcommand{cftchappresnum}{Chapter }
renewcommand{cftchapaftersnum}{ – } 
newlength{tocl}
settowidth{tocl}{bfseriescftchappresnumcftchapaftersnum}
addtolength{cftchapnumwidth}{tocl}

Results aren’t perfect.

One Answer

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

renewcommand{cftchappagefont}{ttfamilyglobalcnta}
renewcommandcftchapafterpnum {%
  makebox[0pt][l]%
     {kern-dimexprlinewidthrelaxmakebox[2em][l]{thecnta}}%
}
renewcommand{cftpartpagefont}{ttfamilyglobalcnta}
renewcommandcftpartafterpnum {%
  makebox[0pt][l]%
     {kern-dimexprlinewidthrelaxmakebox[2em][l]{thecnta}}%
}

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

documentclass{book}
usepackage{tocloft}

newcountcnta
cftsetpnumwidth{0pt}
renewcommandcftsecpagefont {ttfamilyglobalcnta}
renewcommandcftsecafterpnum {%
  makebox[0pt][l]%
     {kern-dimexprlinewidthrelaxmakebox[2em][l]{thecnta}}%
}
renewcommand{cftchappagefont}{ttfamilyglobalcnta}
renewcommandcftchapafterpnum {%
  makebox[0pt][l]%
     {kern-dimexprlinewidthrelaxmakebox[2em][l]{thecnta}}%
vskip7pt
}
renewcommand{cftpartpagefont}{ttfamilyglobalcnta}
renewcommandcftpartafterpnum {%
  makebox[0pt][l]%
     {kern-dimexprlinewidthrelaxmakebox[2em][l]{thecnta}}%
vskip14pt
}

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

renewcommand{cftpartfont}{ttfamilylarge} 
renewcommand{cftchapfont}{rmfamilylargebfseries}

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

renewcommandcftchapafterpnum {%
  makebox[0pt][l]%
     {kern-dimexprlinewidthrelaxmakebox[2em][l]{largethecnta}}%
}

Correct answer by domperor on February 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP