為目錄中的章節條目編寫章節前綴

為目錄中的章節條目編寫章節前綴

我正在尋找允許我將前綴「章節」附加到章節條目的程式碼,僅適用於摘要、聲明等前面的內容,也不適用於參考書目和附錄。下面是我正在尋找的內容。我不希望在候選人聲明、摘要、致謝、LOF、LOT、縮寫清單之前列印章節。我只需要在章節之前列印它。

這是我用過的

\makeatletter

% Per-section appendicies
\newcounter{Appx}
\numberwithin{Appx}{chapter}
\def\@Appx[#1]#2{
\refstepcounter{Appx}
\section*{%
\addcontentsline{toc}{section}{\appendixname\ \Alph{Appx}\quad#1}%
\appendixname\ \Alph{Appx}\quad#2}
}
\def\@@Appx#1{\@Appx[#1]{#1}}
\def\Appx{\@ifnextchar[\@Appx\@@Appx}

% "Chapter" prefix in ToC
\let\@@l@chapter\l@chapter
\def\l@chapter#1{\@@l@chapter{\chaptername\ #1}}

\makeatother

目錄

答案1

有了titlese/titletoc你就可以做到。為了模仿您的問題中顯示的格式,我必須載入套件etoolbox以免包含目錄本身。由於修補環境似乎相當複雜abstract,我建議你將其變成\chapter*命令。我以為你使用的report類別沒有\front/mainmatter命令,所以我提供了它們,為 \frontmatter 提供羅馬編號 - 實際上,我使用small caps羅馬編號(法國印刷術的古老傳統),但如果你不這樣做,很容易改變不喜歡它。

    \documentclass[11pt, a4paper, twoside]{report}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{fourier}
    \usepackage{heuristica}
    \usepackage{microtype}

    \usepackage[pagestyles, explicit]{titlesec}%
    \usepackage{titletoc}%

    \usepackage{etoolbox}
    \newbool{addtoc}%initial value:  false
    \pretocmd{\lsstyle}{\SetTracking[no ligatures = {f}]{encoding = *}{50}}{}{}%

    \titleformat{name = \chapter}[display]%
    {\lsstyle\bfseries\Large\filcenter\vskip-4\baselineskip}
    {\LARGE\chaptername~\thechapter}
    {0.5pc}
    {\vspace{0.5pc}\Huge#1}%
    \titlespacing{\chapter}{0pt}{3\baselineskip}{8\baselineskip}

    \titleformat{name=\chapter, numberless}[display]
    {\vskip-4\baselineskip\lsstyle\bfseries\itshape\large\filcenter}
    {}
    {0.5pc}
    {\vspace{0.5pc}#1}%
    [\ifbool{addtoc}{\addcontentsline{toc}{chapter}{#1}}]%
     \titlespacing{name = \chapter, numberless}{0pt}{2\baselineskip}{8\baselineskip}

      \titlecontents{chapter}[0em]{\lsstyle\smallskip\bfseries}%\vspace{1cm}%
      {\contentslabel[\chaptername~\thecontentslabel]{0em}\hspace{5.6em}}%
      {\renewcommand\thecontentslabel{\relax}\itshape}%numberless%
      {\hfill\contentspage}[\medskip]%
    %
     \titlecontents{section}[4.25em]{\smallskip}%
      {\contentslabel[\thecontentslabel]{2em}}%numbered
      {\hspace*{-1em}}%numberless
      {\hfill\contentspage}[\smallskip]%
    %
     \titlecontents{subsection}[7em]{}%
      {\contentslabel[\thecontentslabel]{2.75em}}%numbered
      {\hspace*{-1em}}%numberless
      {\hfill\contentspage}[\smallskip]

    \renewcommand*{\contentsname}{\upshape TABLE OF CONTENTS \vspace{3\baselineskip}\par \hrule height 1pt\vskip1.5ex Contents\hfill Page No \vskip 1.5ex\par\hrule height 1pt\vskip -8\baselineskip}%
    \apptocmd{\tableofcontents}{\booltrue{addtoc}}{}{}

    \providecommand\frontmatter{\renewcommand\thepage{\scshape\mdseries\roman{page}}}%
    \providecommand\mainmatter{\clearpage\pagenumbering{arabic}}

    \begin{document}

    \frontmatter
    \tableofcontents

     \chapter*{Candidate’s Declaration}
     \chapter*{Abstract}
    \chapter*{Acknowledgments}
    \listoffigures
    \listoftables
    \chapter*{List of Abbreviations}

    \mainmatter

    \chapter{INTRODUCTION}

    \section{Motivation}
    \section{Introduction to Data Mining}
    \newpage

    \section{Steps for Knowledge Discovery in Databases Process}
    \section{Architecture of Data Mining System}
    \newpage

    \section{Datamining Techniques}
    \newpage

    \section{Classification}
    \subsection{Naive Bayes}
    \subsection{J48}
    \newpage

    \subsection{OneR}
    \subsection{ZeroR}
    \subsection{IBk (k nearest neighbor)}
    \section{Association Techniques}
    \section{Description of Heart disease dataset used in Experiment}

    \end{document}

在此輸入影像描述

相關內容