0

Im trying to make a customized Table of Content. The section numbering in the document is as follows:

  1. Title of section. (Underline, in running text, with the first letter capitalized)

In table of Contents, I want it to be under the respective chapter as:

SECTION 1 - Title of Section

I want to set \thesection in a manner that complies with the above requirement.

\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}
4
  • 2
    Welcome to TeX.SE! Could you edit your code to begin with your \documentclass{} and end with \end{document} , a Minimal Working Example (MWE) please. It makes copy and pasting easier when the code can be compiled and also we do not need to guess what commands or packages you are using. There is also way too much code here, could you reduce it down and make it compile for us please? Commented Apr 22, 2023 at 17:49
  • Your request doesn't make any sense. Can you provide a visual (picture) of what you're after? Commented Apr 22, 2023 at 18:16
  • I have updated the question and added relevant pictures for better explanation of the problem Commented Apr 22, 2023 at 19:49
  • Apparently \renewcommand{\cftsecpresnum}{SECTION\ } part of the code is not working. Im unable to get this in action in my code. Commented Apr 24, 2023 at 6:26

1 Answer 1

0

I think that the answer you are looking for is to write "SECTION 1" as the section number in the ToC. Here is the minimal example showing how you do it (run it twice):

\documentclass{book}
\usepackage{tocloft}

\renewcommand{\cftsecpresnum}{SECTION~}
\setlength{\cftsecnumwidth}{8em}

\begin{document}
    
    \tableofcontents
    
    \chapter{Chapter}
    \section{somthing}
    \subsection{Something}
    
    \chapter{Chapter}
    \section{somthing}
    \subsection{Something}
    
\end{document}

To remove the chapter number from the section number you should define the section numbers to not have the chapter number. Add the below code in the preamble for this:

\makeatletter
\renewcommand*{\thesection}{\@arabic\c@section}
\makeatother

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.