下面,perhaps a missing \item
每次处理章节时我都会收到错误。这种情况只发生在第二次编译之后,一旦目录信息建立。下面我有一个 MWE,其中有问题的代码位于顶部附近。该代码是为了确保插入在章节标题下方的“迷你目录”的“前导点”和页码以黑色而不是默认颜色打印。尽管有错误,但结果看起来还是我想要的。我在下面包含的代码比 MWE 严格要求的要多一点,因为我想避免弄乱其他重要部分(例如完整目录)的解决方案。
我该如何修复这个问题以避免这些错误消息 --- 如果\item
其他地方确实缺少 s 则仍然会收到错误消息。
\documentclass[11pt,openany]{memoir}
\usepackage{titletoc}
\usepackage{lipsum}
%%%%%% Problem code is here
\titlecontents{section}
[10em] % left margin
{}% font formatting
{\contentslabel{3em}} % section label and offset
{}
{\color{black}\titlerule*[1pc]{.}\contentspage}
%%%%%%%% end of problem code
\usepackage{color,calc}
\definecolor{ChapRed}{rgb}{.600,.100,.100}
\setsecheadstyle{\color{ChapRed}\large\bfseries}
% coloured chapter font in toc
\let\oldcftchapterfont=\cftchapterfont
\renewcommand{\cftchapterfont}{\color{ChapRed}\oldcftchapterfont}
%% adapted from BlueBox style, pp:43-44
% http://mirror.csclub.uwaterloo.ca/CTAN/info/latex-samples/MemoirChapStyles/MemoirChapStyles.pdf
\newcommand{\RedBarLength}{5em}
\newsavebox{\ChpNumBox}
\makeatletter
\newcommand*{\thickhrulefill}{%
\leavevmode\leaders\hrule height 1\p@ \hfill \kern \z@}
\newcommand*\BuildChpNum[2]{%
\begin{tabular}[t]{@{}c@{}}
\makebox[0pt][c]{#1\strut} \\[.5ex]
\colorbox{ChapRed}{%
\rule[-\RedBarLength]{0pt}{0pt}%
\rule{1ex}{0pt}\color{white}#2\strut
\rule{1ex}{0pt}}%
\end{tabular}}
\makechapterstyle{RedBox}{%
\renewcommand{\chapnamefont}{\large\scshape}
\setlength{\beforechapskip}{-30pt}
\setlength{\midchapskip}{10pt}
\setlength{\afterchapskip}{30pt}
\renewcommand{\printchaptername}{}
\renewcommand{\chapternamenum}{}
\renewcommand{\printchapternum}{%
\sbox{\ChpNumBox}{%
\BuildChpNum{\chapnamefont\@chapapp}%
{\chapnumfont\thechapter}}}
\renewcommand{\printchapternonum}{%
\sbox{\ChpNumBox}{%
\BuildChpNum{\chapnamefont\vphantom{\@chapapp}}%
{\chapnumfont\hphantom{\thechapter}}}}
\renewcommand{\afterchapternum}{}
\renewcommand{\printchaptertitle}[1]{%
\usebox{\ChpNumBox}\hfill
\parbox[t]{\hsize-\wd\ChpNumBox-1em}{%
\vspace{\midchapskip}%
\thickhrulefill\\[10pt]
{\chaptitlefont \textcolor{ChapRed}{##1}}\\
\startcontents[chapters]
\printcontents[chapters]{}{1}{\color{ChapRed}}
}}%
}
\chapterstyle{RedBox}
\begin{document}
\tableofcontents
\chapter{A chapter}
\section{Section}
\lipsum[1]
\section[Short title for this section]{Section 2 with a very, very long title which probably takes more than one line}
\lipsum[1]
\renewcommand{\RedBarLength}{10em}
\chapter{Second chapter}
\section{Section}
\lipsum[1]
\section{Another section}
\lipsum[1]
\section{Another section}
\section{Another section}
\section{Another section}
\section{Another section}
\end{document}
答案1
不要这样做
{\chaptitlefont \textcolor{ChapRed}{##1}}\\
改为这样做
{\chaptitlefont \textcolor{ChapRed}{##1}}\par
章节开头之后放置的内容本质上是一个列表,列表就像从好的地方开始,而不是在\\
段落中间之后,即使视觉效果相似。