樣式目錄

樣式目錄

我正在嘗試建立一個基於此問題的答案的樣式目錄:如何更改目錄的樣式和顏色?

我的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}%
}

問題是「內容」欄的背景與背景不齊平,如下圖所示:

TeX 問題

理想情況下,我希望深灰色矩形與淺色背景的高度和寬度相符。我已經嘗試了一段時間,但我似乎無法弄清楚(說實話,我並不完全理解在此之前的答案中提供的程式碼)。看起來是那麼的微不足道。任何幫助,將不勝感激。

乾杯。

答案1

所以你從未發布過最小工作範例,但由於問題看起來很簡單,我把一個放在一起你提到的問題。您需要新增一行:

\mdfsetup{innerleftmargin=0pt,innerrightmargin=0pt}

這將對目錄中的所有框執行此操作。請注意,只需閱讀mdframed文件就可以為您解決這個問題。在執行任何mdframed命令之前添加它應該會產生以下結果:

顏色目錄

我認為這就是你想要的。希望有幫助。但是,請通讀建立 MWE;你可能會得到一個很多更快、更徹底的答案。

相關內容