带有水平线的自定义目录样式

带有水平线的自定义目录样式

我正在尝试重现一个定制设计的目录(下图),其中每章末尾都有水平线。我是 LaTeX 新手,不确定这样的事情是否可行。我看过这个tocloft软件包,但认为它没有能力重现这种情况。有什么关于如何实现这一点的建议吗?谢谢!

自定义目录设计

答案1

可以使用包建立一个很好的近似值etoc

b

% !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}

在此处输入图片描述

相关内容