使用 tocloft 時目錄中的節編號問題

使用 tocloft 時目錄中的節編號問題

當按照這篇文章的答案中的建議在 pdflatex 中使用 \part 和 tocloft (沒有 fontspec)時將書分成幾部分和章節,我在目錄中的節編號中遇到這樣的問題。

內容

第一部分

1 第1章

1 節1.1

1.1 1.1.1 小節

2 第2章

1 第2.1節

1 第2.2節

1.1 2.2.1 小節

第二部分

3 第3章

2 第3.1節

2.1 3.1.1 小節

不過,文本中的分段很好。

有人可以幫我嗎?謝謝。

序言如下

\documentclass[a4paper,10pt]{book}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage{inputenc}
\usepackage{tabularx}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{textcomp}
\usepackage{xpatch}
\usepackage{tikz}
\usepackage{tocloft}
\usepackage{inputenc}
\usepackage{xspace}
\usepackage{fancyhdr} 
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{}
\fancyhead[RE,LO]{\textcopyright~ Prints 2019}
\fancyfoot[CE,CO]{}
\fancyfoot[LE,RO]{\thepage}

\everymath{\displaystyle}

\newtheorem{prop}{Proposition}[chapter]
\newtheorem{defn}{Definition}[chapter]
\newtheorem{lemma}{Lemma}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{corollary}[prop]{Corollary}
\newtheorem{remark}{Remark}
\newtheorem{example}{Example}[chapter]

\newcommand{\floorceil}[1]{\lceil #1 \rfloor}

\makeatletter
\xpatchcmd{\@thm}{\thm@headpunct{.}}{\thm@headpunct{}}{}{}
\makeatother

\renewcommand{\cftpartfont}{\bfseries\Large\hrule}%add line above part
\renewcommand{\cftpartpagefont}{\bfseries}
\renewcommand{\cftbeforepartskip}{5mm}
\renewcommand{\cftpartafterpnum}{\\\hrule}%add line below part
\cftpagenumbersoff{part}%get rid of part page numbers
\renewcommand{\cftsecindent}{8mm}%control spacing between number and sec title
\renewcommand{\cftsecnumwidth}{4mm}%section indent
\renewcommand{\cftparskip}{4mm}%control line spacing

\begin{document}
\tableofcontents
\part{First part}
\chapter{Chapter1}
\section{Sections1.1}
\subsection{Subsection1.1.1}
\chapter{Chapter2}
\section{Section2.1}
\section{Section2.2}
\subsection{Subsection2.2.1}
\part{Second part}
\chapter{Chapter3}
\section{Section3.1}
\subsection{Subsection3.1.1}
\end{document}

目錄的快照在這裡。目錄1[![][1]]2

答案1

一些意見和建議:

  • 包的長度參數tocloft應該透過修改\setlength,而不是\renewcommand

  • 考慮更換

    \renewcommand{\cftsecindent}{8mm}%control spacing between number and sec title
    \renewcommand{\cftsecnumwidth}{4mm}%section indent
    

    \cftsetindents{chap}{0em}{1.5em}
    \cftsetindents{sec}{1.5em}{2em}
    \cftsetindents{subsec}{3.5em}{2.75em}
    

    顯然,您可以自由修改這些設定以滿足您的偏好和排版需求。


在此輸入影像描述

\documentclass[a4paper,10pt]{book}
\usepackage{mathtools,amssymb,amsthm}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{textcomp}
\usepackage{xpatch}
\usepackage{tikz}
\usepackage{tocloft}
\usepackage{xspace}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{}
\fancyhead[RE,LO]{\textcopyright~ Prints 2019}
\fancyfoot[CE,CO]{}
\fancyfoot[LE,RO]{\thepage}

\everymath{\displaystyle}

\newtheorem{prop}{Proposition}[chapter]
\newtheorem{defn}{Definition}[chapter]
\newtheorem{lemma}{Lemma}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{corollary}[prop]{Corollary}
\newtheorem{remark}{Remark}
\newtheorem{example}{Example}[chapter]

\newcommand{\floorceil}[1]{\lceil #1 \rfloor}

\makeatletter
\xpatchcmd{\@thm}{\thm@headpunct{.}}{\thm@headpunct{}}{}{}
\makeatother

\renewcommand{\cftpartfont}{\hrule\bfseries\Large}%add line above part
\renewcommand{\cftpartpagefont}{\bfseries}
\setlength{\cftbeforepartskip}{5mm}
\renewcommand{\cftpartafterpnum}{\\\hrule}%add line below part
\cftpagenumbersoff{part}%no page numbers for part-level entries

%% commented out:
%\setlength{\cftsecindent}{8mm}% spacing between number and sec title
%\setlength{\cftsecnumwidth}{6mm}%section indent

%% new instructions:
\cftsetindents{chap}{0em}{1.5em}
\cftsetindents{sec}{1.5em}{2em}  % 1st length should be sum of lengths on preceding line
\cftsetindents{subsec}{3.5em}{2.75em}

\setlength{\cftparskip}{4mm}%control line spacing

\begin{document}
\tableofcontents

\part{First part}
\chapter{Chapter1}
\section{Section1.1}
\subsection{Subsection1.1.1}
\chapter{Chapter2}
\section{Section2.1}
\section{Section2.2}
\subsection{Subsection2.2.1}
\part{Second part}
\chapter{Chapter3}
\section{Section3.1}
\subsection{Subsection3.1.1}
\end{document}

相關內容