我正在尝试修改目录的外观。最后它应该看起来像这样: 我设法插入“页面”,但我不知道如何添加线条。
这是一个显示我当前版本的小型工作示例:
\documentclass{article}
\usepackage{tocloft}
\setcounter{tocdepth}{1}
\addtocontents{toc}{~\hfill\textbf{Page}\par}
\begin{document}
\tableofcontents
\newpage
\section{section1}
\subsection{subsection1}
\subsection{subsection2}
\subsection{subsection3}
\section{section2}
\section{section3}
\end{document}
答案1
以下是搭配套餐的建议tocbasic
(不能与一起使用tocloft
):
\documentclass{article}
\usepackage{xcolor}
\usepackage{tocbasic}
\setcounter{tocdepth}{1}
\newcommand*\tocrule[2][-1.5\dp\strutbox]{%
\makebox[0pt][r]{\color{#2}\rule[#1]{\textwidth}{.4pt}}%
}
\newcommand*\pagenumberwithtocrule[2]{#2\tocrule{#1}}
\addtocontents{toc}{%
~\hfill
\textbf{Page}%
\tocrule{red}%
\tocrule[\dimexpr\ht\strutbox+2\dp\strutbox]{red}%
\par
}
\DeclareTOCStyleEntry[
pagenumberformat=\pagenumberwithtocrule{orange}
]{tocline}{section}
\begin{document}
\tableofcontents
\newpage
\section{section1}
\subsection{subsection1}
\subsection{subsection2}
\subsection{subsection3}
\section{section2}
\section{section3}
\end{document}
结果:
答案2
只需重新定义呈现目录条目的宏即可。原始定义在 article.cls 中,我只是添加了一行(参见内联注释)。
编辑:在“页面”周围添加红线:
\documentclass{article}
\usepackage{tocloft}
\setcounter{tocdepth}{1}
%% Need color package for red lines:
\usepackage{color}
\addtocontents{toc}{%
\leavevmode
\raise\baselineskip\hbox{\rlap{\color{red}\rule{\textwidth}{.4pt}}}%
~\hfill\textbf{Page}\par
\rlap{\color{red}\rule{\textwidth}{.4pt}}}
\makeatletter
\renewcommand*\l@section[2]{%
\ifnum \c@tocdepth >\z@
\addpenalty\@secpenalty
\addvspace{1.0em \@plus\p@}%
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\advance\leftskip\@tempdima
\hskip -\leftskip
#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\rlap{\rule{\textwidth}{.4pt}}% <--- This line renders the rule
\endgroup
\fi}
\makeatother
\begin{document}
\tableofcontents
\newpage
\section{section1}
\subsection{subsection1}
\subsection{subsection2}
\subsection{subsection3}
\section{section2}
\section{section3}
\end{document}