我正在尝试制作自定义目录。文档中的章节编号如下:
- 章节标题。(在连续文本中加下划线,首字母大写)
在目录中,我希望它位于相应的章节下,如下所示:
第 1 节 - 章节标题
我想以符合上述要求的方式设置 \thesection。
\documentclass{book}
\usepackage[total={6.5in,8.75in},top=1in, left=2.5cm,right=2.5cm]{geometry}
\usepackage{calc}
\usepackage{float}
\usepackage{ulem}
\useunder{\uline}{\ulined}{}
\renewcommand{\ULdepth}{1.6pt}
\usepackage[T1]{fontenc}
\usepackage{listings}
\usepackage{chngcntr}
\usepackage{tocloft}
\usepackage{url}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{alphalph}
\usepackage{chappg}
\usepackage{refcount}
\usepackage{lastpage}
\pagenumbering{roman}
\newcommand{\partfnt}{\fontsize{12}{12}}
\newcommand{\chapfnt}{\fontsize{12}{12}}
\newcommand{\secfnt}{\fontsize{12}{12}}
\newcommand{\ssecfnt}{\fontsize{12}{12}}
\titleformat{\part}{\centering\normalsize \partfnt}{\underline{\Huge\ PART \thepart - }}{0em}{\Huge \uppercase \uline}
\makeatletter
\def\@makechapterhead#1{%
\vspace*{0}% Space above number
{\parindent \z@ \normalfont
\interlinepenalty\@M
\normalsize\centering \underline{\normalsize\ CHAPTER \thechapter}%
\par\vspace{12pt}% Space between number and title
\centering \underline{\MakeUppercase{#1}}%
\par\vspace{12pt}% Space between title and text
}}
\makeatother
\titleformat{\section}{\centering\normalsize \secfnt}{\underline{\normalsize\ SECTION \thesection - }}{0em}{\uppercase \uline}
\titleformat{\subsection}{\normalfont \ssecfnt}{\thesubsection}{1em}{\uppercase \uline} %FINAL for unbold subsection
\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\ifnum\value{subsection}<10 010\fi\arabic{subsection}.}
\newlength{\mylen} % a "scratch" length
\settowidth{\mylen}{\normalfont \cftsecpresnum\cftsecaftersnum} % extra space
\addtolength{\cftsecnumwidth}{\mylen} % add the extra space
\begin{document}
\renewcommand\contentsname{\underline{CONTENTS}}
\renewcommand{\cfttoctitlefont}{\hfill\normalsize\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}
\setcounter{tocdepth}{1}
\renewcommand{\cftpartfont}{\uppercase \normalfont} % set part font
\renewcommand{\cftpartpagefont}{\normalfont}
\renewcommand{\cftpartdotsep}{100000000000} % adds dots between part name and page number but setting large value will remove dots
\renewcommand{\cftpartleader}{\cftdotfill{\cftpartdotsep}}
\renewcommand{\cftpartafterpnum}{\cftparfillskip} % add space after page number if needed
\renewcommand{\cftpartpresnum}{PART}
\renewcommand{\cftpartaftersnum}{-}
\renewcommand{\cftpartaftersnumb}{\\}
\renewcommand{\cftbeforepartskip}{12}
\renewcommand{\cftchapfont}{\normalfont}
\renewcommand{\cftchappagefont}{\normalfont}
\renewcommand{\cftchapdotsep}{100000000000}
\renewcommand{\cftchapleader}{\cftdotfill{\cftchapdotsep}}
\renewcommand{\cftchapaftersnum}{.}
\renewcommand{\cftchapaftersnumb}{\\}
\renewcommand{\cftbeforechapskip}{12}
\renewcommand{\cftchapnumwidth}{3em}
\renewcommand{\cftsecfont}{\normalfont}
\renewcommand{\cftsecpagefont}{\normalfont}
\renewcommand{\cftsecdotsep}{100000000000}
\renewcommand{\cftsecleader}{\normalfont\cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsecpresnum}{SECTION\ }
\renewcommand{\cftsecaftersnum}{\ -\ }
\renewcommand{\cftsecaftersnumb}{\\}
\renewcommand{\cftsecindent}{5em}
\tableofcontents
\addtocontents{toc}{\textbf{CHAPTER}\hfill\textbf{SUBJECT}\hfill\textbf{PAGE NO}\par}
\addcontentsline{toc}{chapter}{\hspace{5em} \normalfont Promulgation}
\addcontentsline{toc}{chapter}{\hspace{5em} \normalfont Improvement}
\newpage
\clearpage
\renewcommand\thepage{\arabic{chapter}-\arabic{page}}
\part{General}
\setcounter{page}{1}
\chapter{Chapter}
ABCD
\section{somthing}
something
\subsection{Something}
Something
\part{Special}
\setcounter{page}{1}
\chapter{Chapter}
ABCD
\section{somthing}
something
\subsection{Something}
Something
\end{document}