答案1
可以使用包建立一个很好的近似值etoc
% !TeX TS-program = pdflatex
\documentclass[12pt,a4paper]{book}
\usepackage[thin,medium]{josefin}
\usepackage[T1]{fontenc}
\usepackage[x11names]{xcolor}
\usepackage{etoc}
\newcommand{\NiceTOC}{%
\begingroup%
\newlength{\tocleftmargin}
\setlength{\tocleftmargin}{4em} % left margin indent <<<<<<<<<<<<<
\etocsetstyle{chapter}{}{} %
{\etocsavedchaptertocline{\sffamily\color{SlateGray4}\hspace{\tocleftmargin}\etocname}{\etocpage}
\vskip-0.5em%
\dimen0\hsize%
\advance\dimen0-\tocleftmargin%
\moveright\tocleftmargin\vbox{{\color{SlateGray4}\hrule width\dimen0}}\vskip-1em%
}{}%
\etocsettocstyle{\chapter*{\thispagestyle{empty}\sffamily \color{SteelBlue3} \Huge Contents}}
{\vskip-0.2em\color{DeepSkyBlue3}\noindent\hspace*{\tocleftmargin}\rule{\dimen0}{2pt}}
\tableofcontents
\endgroup}
\begin{document}
\NiceTOC
\chapter*{Executive Summary}
\addcontentsline{toc}{chapter}{Executive Summary}%
\chapter*{Assessment Scope}
\addcontentsline{toc}{chapter}{Assessment Scope}%
\chapter*{Methodology}
\addcontentsline{toc}{chapter}{Methodology}%
\chapter*{Attack Path Narrative}
\addcontentsline{toc}{chapter}{Attack Path Narrative}%
\chapter*{Risk Ratings}
\addcontentsline{toc}{chapter}{Risk Ratings}%
\chapter*{Issues Identified}
\addcontentsline{toc}{chapter}{Issues Identified}%
\chapter*{Appendix A: Engagement Cleanup}
\addcontentsline{toc}{chapter}{Appendix A: Engagement Cleanup}%
\chapter*{Appendix B: Brief Description}
\addcontentsline{toc}{chapter}{Appendix B: Brief Description}%
\end{document}
答案2
使用该包可以做到这一点tocloft
。
% toclinesprob.tex SE 595297
\documentclass{report}
\usepackage{tocloft}
\usepackage{color}
% length of rule below chapters
\newlength{\ruleit} \setlength{\ruleit}{\textwidth}
% put the rule after chapter page numbers
\renewcommand{\cftchapafterpnum}{\hspace{-2.5em}\mbox{}\\[0.5\baselineskip]
\hspace*{-1.5em}\rule{\ruleit}{0.4pt}}
% change Contents font to blue
\renewcommand{\cfttoctitlefont}{\color{blue}\huge\bfseries}
% no \chapter, \section, etc numbers
\setcounter{secnumdepth}{-1}
\begin{document}
\tableofcontents
\chapter{First chapter}
\chapter{Second chapter}
% put this after last \chapter for thick blue line at the bottom of the ToC
\addtocontents{toc}{\vspace*{-\baselineskip}\color{blue}\rule{\ruleit}{2pt}}
\end{document}