我在使用包时尝试将目录添加到书签中tcolorbox
,我正在使用memoir
类。以下是我的 MWE。
\documentclass[oneside]{memoir}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage[bookmarks=true]{hyperref}
\begin{document}
\frontmatter
\chapter{Sample front matter chapter}
\lipsum[1-2]
\newpage
\begin{tcolorbox}[
breakable,
enhanced jigsaw,title={\contentsname},fonttitle=\bfseries\Large,
% colback=white,% colback=yellow!10!white,
opacityback=0,
colframe=red!50!black,before=\par\bigskip\noindent,
% interior style={fill overzoom image=goldshade.png,fill image opacity=0.25},
colbacktitle=red!50!yellow!75!black,
enlargepage flexible=\baselineskip,pad at break*=3mm,
% watermark color=yellow!75!red!25!white,
% watermark text={\bfseries\Large \contentsname},
attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
boxed title style={enhanced,boxrule=0.5mm,
frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west) -- (frame.north west)
-- (frame.north east) -- ([xshift=4mm]frame.east)
-- (frame.south east) -- (frame.south west) -- cycle; },
interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
-- (interior.north west) -- (interior.north east)
-- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
-- cycle;} },
% drop fuzzy shadow
]
\makeatletter
\small
\@starttoc{toc}
\makeatother
% \addcontentsline{toc}{chapter}{test}
\end{tcolorbox}
\mainmatter
\part{Test Part One}
\chapter{Test Chapter One}
\lipsum[1]
\section{Test Section One}
\lipsum[1]
\end{document}
答案1
就这样!
在宏中挖掘\tableofcontents
我发现了负责在目录中创建目录条目的行:
\phantomsection% <- Add a placeholder section
\addcontentsline{toc}{chapter}{\contentsname}% <- Add the ToC entry to the .toc file
然后我就在 之前添加了这两个内容\@starttoc{toc}
。
另外,我擅自将\thispagestyle{empty}
目录页中的上一章的标题从页眉中删除。
\documentclass[oneside]{memoir}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage[bookmarks=true,colorlinks]{hyperref}
\begin{document}
\frontmatter
\chapter{Sample front matter chapter}
\lipsum[1-2]
\newpage
\begin{tcolorbox}[
breakable,
enhanced jigsaw,title={\contentsname},fonttitle=\bfseries\Large,
% colback=white,% colback=yellow!10!white,
opacityback=0,
colframe=red!50!black,before=\par\bigskip\noindent,
% interior style={fill overzoom image=goldshade.png,fill image opacity=0.25},
colbacktitle=red!50!yellow!75!black,
enlargepage flexible=\baselineskip,pad at break*=3mm,
% watermark color=yellow!75!red!25!white,
% watermark text={\bfseries\Large \contentsname},
attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
boxed title style={enhanced,boxrule=0.5mm,
frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west) -- (frame.north west)
-- (frame.north east) -- ([xshift=4mm]frame.east)
-- (frame.south east) -- (frame.south west) -- cycle; },
interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
-- (interior.north west) -- (interior.north east)
-- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
-- cycle;} },
% drop fuzzy shadow
]
\thispagestyle{empty}% <- SUGGESTION
\makeatletter
\small
% HERE ↓↓↓↓↓↓↓↓
\phantomsection
\addcontentsline{toc}{chapter}{\contentsname}
% HERE ↑↑↑↑↑↑↑↑
\@starttoc{toc}
\makeatother
\end{tcolorbox}
\mainmatter
\part{Test Part One}
\chapter{Test Chapter One}
\lipsum[1]
\section{Test Section One}
\lipsum[1]
\end{document}
顺便说一句,目录很棒:)
答案2
使用tcolorbox
工具,即定义一个特殊的并tocbox
说出来然后自动执行。list inside
list type=chapter
\documentclass[oneside]{memoir}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage[bookmarks=true]{hyperref}
\newtcolorbox[list inside=toc,list type=chapter]{tocbox}{%
breakable,
enhanced jigsaw,title={\contentsname},fonttitle=\bfseries\Large,
% colback=white,% colback=yellow!10!white,
opacityback=0,
colframe=red!50!black,before=\par\bigskip\noindent,
% interior style={fill overzoom image=goldshade.png,fill image opacity=0.25},
colbacktitle=red!50!yellow!75!black,
enlargepage flexible=\baselineskip,pad at break*=3mm,
% watermark color=yellow!75!red!25!white,
% watermark text={\bfseries\Large \contentsname},
attach boxed title to top center={yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
boxed title style={enhanced,boxrule=0.5mm,
frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west) -- (frame.north west)
-- (frame.north east) -- ([xshift=4mm]frame.east)
-- (frame.south east) -- (frame.south west) -- cycle; },
interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
-- (interior.north west) -- (interior.north east)
-- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
-- cycle;} },
% list entry=\contentsname
% drop fuzzy shadow
}
\begin{document}
\frontmatter
\chapter{Sample front matter chapter}
\lipsum[1-2]
\newpage
\begin{tocbox}
\makeatletter
\small
\@starttoc{toc}
\makeatother
\end{tocbox}
\mainmatter
\part{Test Part One}
\chapter{Test Chapter One}
\lipsum[1]
\section{Test Section One}
\lipsum[1]
\end{document}
答案3
与其他类不同,该类memoir
设置\tableofcontents
了目录并将其标题添加到目录中,而它的\tableofcontents*
行为与tablofcontents
其他类一样,并没有将其标题添加到目录中。(回想起来,这可能是一个不幸的设计决定)。
我认为对你的 MWE 进行简单的更改就能得到你想要的东西:
替换以下行:
\makeatletter
\small
\@starttoc{toc}
\makeatother
\addcontentsline{toc}{chapter}{test}
\end{tcolorbox}
和
\small
\tableofcontents
\addcontentsline{toc}{chapter}{test} % do you really need this in your final doc?
\end{tcolorbox}