
我正在嘗試建立一個基於此問題的答案的樣式目錄:如何更改目錄的樣式和顏色?
我的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}%
}
問題是「內容」欄的背景與背景不齊平,如下圖所示:
理想情況下,我希望深灰色矩形與淺色背景的高度和寬度相符。我已經嘗試了一段時間,但我似乎無法弄清楚(說實話,我並不完全理解在此之前的答案中提供的程式碼)。看起來是那麼的微不足道。任何幫助,將不勝感激。
乾杯。