章节的内容通过以下代码放入 tcolor。我们如何修改章节的代码。我的代码已创建\mysectionnamebox
以添加章节的内容行。谢谢您的帮助!
\documentclass[12pt,a4paper,openany]{book}
\usepackage[most]{tcolorbox}
\usepackage{tocloft}
\usetikzlibrary{calc,angles,intersections,shapes.geometric,arrows,decorations.markings,arrows.meta,patterns.meta,patterns}
\definecolor{darkmidnightblue}{rgb}{0.0, 0.2, 0.4}
\newtcolorbox{chapternamebox}[1][]{%
enhanced jigsaw,
valign=center,
interior style={left color={darkmidnightblue!30!darkmidnightblue},
right color={darkmidnightblue!90!darkmidnightblue}},
colframe={white},
boxrule={1pt},
colupper={white},
size=small,
boxsep=2pt,
sharp corners,
fontupper={\sffamily\bfseries\large},
nobeforeafter,
equal height group=chaptertoc,
left=0.25cm,
overlay={
\path (frame.north west) coordinate (A)
(frame.south west) coordinate (B)
($(A)!0.5!(B)$) coordinate (O)
($(O)!1!90:(B)$) coordinate (C);
\draw[thick,white] (A)--(B)--(C)--cycle;
}
#1,
}
\newtcolorbox{sectionnamebox}[1][]{%
enhanced jigsaw,
colframe={white},
boxrule={1pt},
size=small,
boxsep=3pt,
sharp corners,
colback=yellow!15,
sidebyside,
sidebyside align=center,
bicolor,
righthand width=1.25cm,
colbacklower=cyan!25,
fontupper={\sffamily},
nobeforeafter,
#1,
}
\newcommand{\mychapternamebox}[3][]{%
\begin{chapternamebox}[#1]
\begin{tabular}{p{0.2\linewidth}p{0.75\linewidth}}
#2%
\end{tabular}
\end{chapternamebox}%
}
\newcommand{\mysectionnamebox}[3][]{%
\begin{sectionnamebox}[#1]
#2
\tcblower
\begin{flushright}
#3
\end{flushright}
\end{sectionnamebox}%
}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@chapter}{%
\addcontentsline{toc}{chapter}%
{\protect\numberline{\thechapter}#1}%
}{%
\addtocontents{toc}{\protect\cftpagenumbersoff{chapter}}
\addcontentsline{toc}{chapter}{\protect\mychapternamebox[width=\linewidth]{\protect\chaptername{} \thechapter}{#1}}%%
\addtocontents{toc}{\protect\cftpagenumberson{chapter}}%
}{}{}
\xpatchcmd{\@section}{%
\addcontentsline{toc}{section}%
{\protect\numberline{\section}#1}%
}{%
\addtocontents{toc}{\protect\cftpagenumbersoff{section}}
\addcontentsline{toc}{section}{\protect\mysectionnamebox[width=\linewidth]{\protect\thesection. #1}{\thepage}}%%
\addtocontents{toc}{\protect\cftpagenumberson{section}}%
}{}{}
\makeatother
\begin{document}
\tableofcontents
\chapter{First Chapter}
\section{First Section}
\section{Second Section}
\mysectionnamebox{A}{B}
\chapter{Second Chapter}
\section{First Section}
\addcontentsline{toc}{section}{\protect\mysectionnamebox[width=\linewidth]{\protect\thesection. First Section}{\thepage}}%%
\section{Second Section}
\chapter*{Third Chapter}
\end{document}