我想使用遵循花哨的目录在我的 memoir 文档中。但是,它似乎\usepackage{tocloft}
与 memoir 不兼容。我是否可以将它与 memoir 一起使用?应该进行哪些修改?
book
由于我使用了花哨的回忆录章节样式,因此我无法改变。
答案1
这是使用 的链接答案的版本memoir
。主要的变化是重命名tocloft
命令(在 中略有不同memoir
),并重新定义memoir
\@chapter
命令,而不仅仅是修补它。
\documentclass[10pt,a4paper,openany]{memoir}
% Original code from https://tex.stackexchange.com/a/301026/2693
% adapted to work with memoir instead of book+tocloft
\usepackage[x11names,dvipsnames,svgnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{xparse}
\usepackage{array}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\makeatletter
\tcbset{%
chapternumberbox/.style={%
colframe=black,
colback={blue!60!white},
colupper={white},
fontupper={\bfseries\normalsize},
halign=center,
valign=center,
size=small,
nobeforeafter,
equal height group=chaptertoc,
left skip=0pt,
right skip=0pt,
},
chapternamebox/.style={%
left skip=0pt,
right skip=0pt,
enhanced jigsaw,
valign=center,
interior style={left color={blue!60!white},right color={blue!15!white}},
colframe={black},
boxrule={1pt},
colupper={black},
size=small,
fontupper={\bfseries\normalsize},
nobeforeafter,
equal height group=chaptertoc,
}
}
\newtcolorbox{chapternumberboxinternal}[1][]{%
chapternumberbox,
#1
}
\newtcolorbox{chapternamebox}[1][]{%
chapternamebox,
#1,
}
\NewDocumentCommand{\chapternumberbox}{O{}m}{%
\begin{chapternumberboxinternal}[#1,width={\cftchapternumwidth}]%-\kvtcb@left@rule-\kvtcb@right@rule}]
#2%
\end{chapternumberboxinternal}%
}
\NewDocumentCommand{\mychapternamebox}{O{}+mm}{%
\begin{chapternamebox}[#1,width={\dimexpr\tocwidth-\cftchapternumwidth+\marginparsep}]
\begin{tabular}{@{}p{\kvtcb@leftupper}@{}@{}p{\dimexpr\tocwidth-\cftchapternumwidth-\@pnumwidth-\kvtcb@leftupper-\marginparsep}@{}@{}R{\dimexpr\@pnumwidth}@{}@{}p{\kvtcb@rightupper}@{}}
& #2
\end{tabular}
\end{chapternamebox}%
}
\usepackage{xpatch}
\usepackage{xprintlen}
\newlength\tocwidth
\renewcommand{\cftchapternumwidth}{2.5cm}
\setlength{\cftchapterindent}{0pt}
\AtBeginDocument{%
\setlength{\tocwidth}{\linewidth}
}
\def\@chapter[#1]#2{%
\m@mpn@new@chaptrue%
\m@mpn@new@schapfalse%
\def\f@rbdy{#2}%
\ifx\ch@pt@c\@empty % no optional args
\def\f@rtoc{#2}%
\def\f@rhdr{#2}%
\else % at least one opt arg
\let\f@rtoc\ch@pt@c
\ifx\@empty#1\@empty
\let\f@rhdr\ch@pt@c
\else
\def\f@rhdr{#1}%
\fi
\fi
\m@m@Andfalse
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\m@m@Andtrue
\fi
\fi
\ifm@m@And
\refstepcounter{chapter}%
\fi
\ifartopt
\@makechapterhead{#2}%
\@afterheading
\chaptermark{\f@rhdr}%
\else
\chaptermark{\f@rhdr}
\insertchapterspace
\if@twocolumn
\@topnewpage[\@makechapterhead{#2}]%
\else
\@makechapterhead{#2}%
\fi
\@afterheading
\fi
\@nameuse{chapter@f@rtoc@before@write@hook}%
\mempreaddchaptertotochook%
\ifm@m@And
\ifanappendix
\addcontentsline{toc}{appendix}{%
\protect\chapternumberline{\thechapter}\f@rtoc}%
\memappchapinfo{\thechapter}{\f@rtoc}{\f@rhdr}{#2}%
\else
\addtocontents{toc}{\protect\cftpagenumbersoff{chapter}}
\addcontentsline{toc}{chapter}{\chapternumberbox{\protect\chaptername\ \thechapter}%
\protect\mychapternamebox[]{\f@rtoc}{\thepage}}%
\addtocontents{toc}{\protect\cftpagenumberson{chapter}}%
\memchapinfo{\thechapter}{\f@rtoc}{\f@rhdr}{#2}%
\fi
\else
\addtocontents{toc}{\protect\cftpagenumbersoff{chapter}}
\addcontentsline{toc}{chapter}{\chapternumberbox{\protect\chaptername\ \thechapter}
\protect\mychapternamebox[]{\f@rtoc}{\thepage}}%%
\addtocontents{toc}{\protect\cftpagenumberson{chapter}}%
\ifanappendix
\memappchapinfo{}{\f@rtoc}{\f@rhdr}{#2}%
\else
\memchapinfo{}{\f@rtoc}{\f@rhdr}{#2}%
\fi
\fi
\mempostaddchaptertotochook%
\ifheadnameref\M@gettitle{\f@rhdr}\else\M@gettitle{\f@rtoc}\fi%
\memendofchapterhook%
}
\makeatother
\begin{document}
\tableofcontents
\chapter{First Chapter}
\section{First Section}
\section{Second Section}
\chapter{Second Chapter}
\section{First Section}
\section{Second Section}
\chapter[Theory on Brontosaurs]{Third Chapter with an excessively long title that should be avoided!}
\end{document}