我正在尝试创建一个基于此问题的答案的样式目录:如何更改目录的样式和颜色?
我拥有的 TeX 如下所示:
\definecolor{secnum}{RGB}{241,129,39}
\definecolor{ptcbackground}{RGB}{247,247,247}
\definecolor{ptctitle}{RGB}{177,177,177}
\pretocmd{\tableofcontents}{\begin{mdframed}[backgroundcolor=ptcbackground,hidealllines=true]}{}{}
\apptocmd{\tableofcontents}{\end{mdframed}}{}{}
\patchcmd{\tableofcontents}{\begin{mdframed}[backgroundcolor=ptctitle,hidealllines=true]}{}{}
\titlecontents{section}
[3.3em]{\sffamily}
{\color{secnum}\contentslabel{2.3em}\normalcolor}{}
{\titlerule*[1000pc]{.}\contentspage\\\hspace*{-3em}\vspace*{-3pt}%
\color{white}\rule{\dimexpr\textwidth-20pt\relax}{0pt}}
\titlecontents{lsection}
[3.3em]{\sffamily}
{\color{secnum}\contentslabel{2.3em}\normalcolor}{}
{\titlerule*[1000pc]{.}\contentspage\\\hspace*{-5.8em}\vspace*{-3pt}%
\color{white}\rule{\dimexpr\textwidth-15.5pt\relax}{0pt}}
\titlecontents{lsubsection}
[5.8em]{\sffamily}
{\color{secnum}\contentslabel{2.3em}\normalcolor}{}
{\titlerule*[1000pc]{.}\contentspage\\\hspace*{-5.8em}\vspace*{-3pt}%
\color{white}\rule{\dimexpr\textwidth-15.5pt\relax}{0pt}}
\titlecontents{subsection}
[5.8em]{\sffamily}
{\color{secnum}\contentslabel{2.3em}\normalcolor}{}
{\titlerule*[1000pc]{.}\contentspage\\\hspace*{-5.8em}\vspace*{-3pt}%
\color{white}\rule{\dimexpr\textwidth-15.5pt\relax}{0pt}}
\makeatletter
\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 0em \@plus\p@
\setlength\@tempdima{0em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode
\advance\@tempdima
\hskip
\colorbox{ptctitle}{\strut%
\makebox[\dimexpr\textwidth\fboxsep100pt\relax][l]{%
\color{white}\bfseries\sffamily#1%
\nobreak\hfill\nobreak\hb@xt@\@pnumwidth{\hss #2}}}\par\smallskip
\penalty\@highpenalty
\endgroup
\fi}
\makeatother
\newcommand\PartialToC{%
\startcontents[chapters]%
\begin{mdframed}[backgroundcolor=ptcbackground,hidealllines=true]
\printcontents[chapters]{1}{1}{\colorbox{ptctitle}{%
\parbox[t][][t]{\dimexpr\textwidth-2\fboxsep\relax}{%
\strut\color{white}\bfseries\sffamily\makebox[.5em]{%
}\large Contents}}\vskip5pt}
\end{mdframed}%
}
问题是“内容”栏的背景与背景不齐平,如下图所示:
理想情况下,我希望深灰色矩形与浅色背景的高度和宽度相匹配。我尝试了一段时间,但似乎无法弄清楚(说实话,我并不完全理解之前答案中提供的代码)。这似乎微不足道。任何帮助都将不胜感激。
干杯。