在左侧显示目录中的所有页码?

在左侧显示目录中的所有页码?

我正在尝试在目录左侧显示页码。我使用了使用 tocloft 将目录中的页码移到标题左侧 线程并且能够让数字在各部分的左侧正确显示。

我无法修改代码以将章节和部分编号也移到左侧。有没有什么办法可以创建一个简单的解决方案将所有页码移到左侧?

这是我当前的代码:

\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}

现在它看起来是这样的:

目录 – 混合编号

请注意,我还使用以下代码在章节名称中添加“章节”和连字符:

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

结果并不完美。

答案1

\cftsecpagefont您已使用更新和的技巧\cftsecafterpnum。相同的方法在章节和部分中起作用,如下所示:

\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}}%
}

以下是一个较小的工作示例,可简化您的文档:

\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}

结果:结果


编辑:关于页码大小的修改

您可以将size命令添加到\cftpartafterpnum\cftchapafterpnum和中\cftsecafterpnum

例如\large插入\cftchapafterpnum

\renewcommand\cftchapafterpnum {%
  \makebox[0pt][l]%
     {\kern-\dimexpr\linewidth\relax\makebox[2em][l]{\large\the\cnta}}%
}

相关内容