我正在用\documentclass[12pt]{book}
它来整理一本 500 页的书。.tex 文件变得非常大且复杂。因此,我遇到了与目录的冲突。
\setcounter{tocdepth}{3}
尽管有章节和小节,但我只能获得章节。
这是我正在使用的代码:
\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{import}
\usepackage{fullpage}
\usepackage{fontspec}
\usepackage{enotez}
\usepackage{afterpage}
\usepackage{xcolor}
\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=true,options={-s index-style.ist}]
\usepackage{enumitem,amssymb}
\usepackage{titlesec}
\usepackage{totcount}
% Font Selection
\setmainfont[
BoldFont={DMSans-Bold.ttf},
ItalicFont={DMSans-Italic.ttf},
BoldItalicFont={DMSans-BoldItalic.ttf},
]{DMSans-Regular.ttf}
\setmonofont{DMMono-Regular.ttf}
% Captions
\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}}}%
}%
}
% Footer
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhf{}
\fancyfoot[RO]{\footnotesize\ttfamily{\leftmark \hspace*{55pt} \thepage}}
\fancyfoot[LE]{\footnotesize\ttfamily{\thepage \hspace*{60pt} Solving Product}}
\setlength{\headheight}{13.6pt}
\renewcommand{\headrulewidth}{0pt}
% Redefine the plain page style
\fancypagestyle{plain}{%
\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
\setcounter{tocdepth}{3}
\begin{document}
\flushbottom
\frontmatter
\newpage
\chapter{Introduction}
\section*{Sub-title A}
\section*{Sub-title B}
\section*{Sub-title C}
\chapter{Conclusion}
\section*{Sub-title A}
\section*{Sub-title B}
\section*{Sub-title C}
\end{document}
目前的 ToC 如下:
为什么不显示其他级别?有什么想法吗?
答案1
看起来您不希望对您的部分进行编号。建议的方法是:
% in the preamble
\setcounter{secumdepth}{0} % no numbers below chapters
% in the document body
\section{One} % not \section*
% text
\section{two} % not section*
% text
这些部分将出现在目录中,但未编号。无需任何包。A
答案2
您可以在 \titleformat 中使用无数字键:
\titleformat{name =\section, numberless}[display] {\huge\bfseries}{}{0pt}{\fontsize{22}{28}\selectfont\addcontentsline{toc}{section}}