我一直在玩这个漂亮的 ToC,目的是简化它以满足我的需求。我已经成功做到了这一点,但是当我尝试将它实现到更大的文件中时,\frontmatter
似乎会导致错误,然而代码在没有的情况下运行却没有错误\frontmatter
。
产生的错误是:
! Extra }, or forgotten \endgroup. \ttl@tocentry ... #5{#7}\strut \kern \z@ }\fi {#6} \ifcase #1\relax \ifttl@fr... l.1 \contentsline {chapter}{A chapter}{i}
代码中没有缺失}
,所以存在一些更深层次的问题。我一直在研究这个错误,但不知道如何修复它。
梅威瑟:
\documentclass[11pt]{book}
\usepackage{framed}
\usepackage[compact,pagestyles,clearempty]{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}
% % % pretty ToC modified from https://tex.stackexchange.com/questions/35825/pretty-table-of-contents
\patchcmd{\tableofcontents}{\contentsname}{\rmfamily\contentsname}{}{}
\renewenvironment{leftbar}
{\def\FrameCommand{\hspace{26.7em}%
{\vrule width 2pt depth 3pt}\hspace{1em}}%
\MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
}
{\endMakeFramed}
\titlecontents{chapter}
[0em]{\vspace*{0.3\baselineskip}}
{\parbox{14.8em}{%
\hfill\huge\rmfamily\bfseries\thecontentspage}%
\vspace*{-2.4\baselineskip}\leftbar\textsc{\normalsize\chaptername~\thecontentslabel}\\\normalsize\rmfamily}
{}{\endleftbar}
% % %
\begin{document}
\tableofcontents
%\frontmatter %untoggle to see error(s)
\chapter{A chapter}
\mainmatter
\chapter{Another chapter}
\chapter{Another chapter}
\end{document}
答案1
有了前言,章节就不编号了。的论点titlecontents
是空的,所以你最终得到的是一篇\endleftbar
没有开头的孤独的文章\leftbar
:
\documentclass[11pt]{book}
\usepackage{framed}
\usepackage[compact,pagestyles,clearempty]{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}
% % % pretty ToC modified from https://tex.stackexchange.com/questions/35825/pretty-table-of-contents
\patchcmd{\tableofcontents}{\contentsname}{\rmfamily\contentsname}{}{}
\renewenvironment{leftbar}
{\def\FrameCommand{\hspace{26.7em}%
{\vrule width 2pt depth 3pt}\hspace{1em}}%
\MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
}
{\endMakeFramed}
\titlecontents{chapter}
[0em]{\vspace*{0.3\baselineskip}}
{\parbox{14.8em}{%
\hfill\huge\rmfamily\bfseries\thecontentspage}%
\vspace*{-2.4\baselineskip}\leftbar\textsc{\normalsize\chaptername~\thecontentslabel}\\\normalsize\rmfamily}
{\parbox{14.8em}{% <----- new
\hfill\huge\rmfamily\bfseries\thecontentspage}% <---new
\vspace* {-2.4\baselineskip}\leftbar\textsc{\normalsize\chaptername~\thecontentslabel}\\\normalsize\rmfamily}
{\endleftbar}
% % %
\begin{document}
\tableofcontents
\frontmatter %untoggle to see error(s)
\chapter{A chapter}
\mainmatter
\chapter{Another chapter}
\chapter{Another chapter}
\end{document}