我正在尝试创建如下所示的目录:
我已经尝试了不同的方法来实现它titletoc
,但tocloft
我没有得到想要的输出。我希望链接是可点击的,这样我就可以转到被点击的部分。以下是目前的代码:
\documentclass[12pt]{article}
\usepackage[table]{xcolor}
\usepackage[hidelinks]{hyperref}
\usepackage[english]{babel}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\begin{document}
\tableofcontents
\section*{Document Revision History}
\section*{Contacts}
\section{Executive Summary}
\subsection{Introduction}
\subsection{Test Approach and Methodology}
\subsection{SCOPE}
\section{Assessment Summary And Findings Overview}
\section{Findings Technical Details}
\subsection{Vuln 1}
\subsubsection{Description}
\subsubsection{Code Location}
\subsubsection{Recommendation}
\end{document}
答案1
部分答案。由于色盲,我不懂颜色,但以下内容确实将目录条目排版为左对齐,没有虚线前导符
% colouredtocprob.tex SE 581740
\documentclass[12pt]{article}
\usepackage[table]{xcolor}
\usepackage[hidelinks]{hyperref}
\usepackage[english]{babel}
\usepackage{tocloft}
\setlength{\cftsecindent}{0pt}
\setlength{\cftsubsecindent}{0pt}
\setlength{\cftsubsubsecindent}{0pt}
\renewcommand{\cftsecdotsep}{\cftnodots}
\renewcommand{\cftsubsecdotsep}{\cftnodots}
\renewcommand{\cftsubsubsecdotsep}{\cftnodots}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\begin{document}
\tableofcontents
\section*{Document Revision History}
\section*{Contacts}
\section{Executive Summary}
\subsection{Introduction}
\subsection{Test Approach and Methodology}
\subsection{SCOPE}
\section{Assessment Summary And Findings Overview}
\section{Findings Technical Details}
\subsection{Vuln 1}
\subsubsection{Description}
\subsubsection{Code Location}
\subsubsection{Recommendation}
\end{document}
答案2
这不是一个好的建议(也借用了先生的Peter Wilson
建议),但它部分有效:
\documentclass[12pt]{article}
\usepackage[table]{xcolor}
\usepackage[hidelinks]{hyperref}
\usepackage[english]{babel}
\usepackage{framed}
\usepackage{tocloft}
\setlength{\cftsecindent}{0pt}
\setlength{\cftsubsecindent}{0pt}
\setlength{\cftsubsubsecindent}{0pt}
\renewcommand{\cftsecdotsep}{\cftnodots}
\renewcommand{\cftsubsecdotsep}{\cftnodots}
\renewcommand{\cftsubsubsecdotsep}{\cftnodots}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\begin{document}
\colorlet{shadecolor}{black!75}
\tableofcontents
\newpage
\addtocontents{toc}{\protect\begin{snugshade}\color{white}}
\section*{Document Revision History}
\section*{Contacts}
\section{Executive Summary}
\addtocontents{toc}{\protect\end{snugshade}\color{black}}
\addtocontents{toc}{\protect\colorlet{shadecolor}{black!40}\begin{snugshade}\color{white}}
\subsection{Introduction}
\subsection{Test Approach and Methodology}
\subsection{SCOPE}
\addtocontents{toc}{\protect\end{snugshade}\color{black}}
\addtocontents{toc}{\protect\begin{snugshade}\color{white}}
\section{Assessment Summary And Findings Overview}
\section{Findings Technical Details}
\addtocontents{toc}{\protect\end{snugshade}\color{black}}
\addtocontents{toc}{\protect\colorlet{shadecolor}{black!40}\begin{snugshade}\color{white}}
\subsection{Vuln 1}
\subsubsection{Description}
\subsubsection{Code Location}
\subsubsection{Recommendation}
\addtocontents{toc}{\protect\end{snugshade}\color{black}}
\end{document}