Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In the following, I get a perhaps a missing \item error each time a chapter is processed. This occurred only after the second compilation, once the table of contents information is built. Below I have a MWE where the offending code is near the top. That code is to ensure that the "leading dots" and page number for the "mini table of contents" inserted below the chapter title are printed in black instead of the default color. The result looks the way I want it, in spite of the errors. I have included a little bit more code below than that strictly required for a MWE as I want to avoid solutions that would mess up other important parts (for instance the full table of contents).

How could I fix this to avoid these error messages --- while still getting error messages if truly missing \items elsewhere.

\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}
share|improve this question
    
Could you please try to remove from your heading what can be removed in such way that the error still occurs? I think that this way you might even find and solve the problem yourself... –  tohecz Mar 29 '12 at 7:43
3  
To quote the LaTeX Companion: The error message is produced by an \addvspace command when encountered in horizontal mode. The follow-up remark about "perhaps a missing \item is unfortunately seldom correct. The problematic code is imho not in the \titlecontents: It only clashes with something you are doing in the long chapter redefinitions. –  Ulrike Fischer Mar 29 '12 at 9:08
add comment

1 Answer 1

up vote 14 down vote accepted

Don't do this

{\chaptitlefont \textcolor{ChapRed}{##1}}\\

do this instead

 {\chaptitlefont \textcolor{ChapRed}{##1}}\par

The contents that you are placing after the chapter opening are essentially a list and lists like starting in good places not after \\ which is mid-paragraph even if the visual effect is similar.

share|improve this answer
2  
david, would you agree that the "missing item" is an unfortunate error message in this circumstance, as in an awful lot of cases where it occurs? (yes, i know it's leslie's message, and all that jazz, but...) –  wasteofspace Mar 29 '12 at 9:21
9  
@wasteofspace, It is rumored that in the 25 year history of LaTeX there have been occasions when this error has been caused by a missing item, but that's only a rumor that has not been officially confirmed. –  David Carlisle Mar 29 '12 at 9:46
    
Does the missing item error have something to do with the fact that a lot of latex's environments are defined in terms of the list and trivlist environment? –  cmhughes Apr 1 '12 at 19:40
    
@cmhughes, hard to say really. You get the error if something tries to execute \addvspace in horizontal (LR) mode. \addvspace is latex's normal way of combining vertical space between display constructs, list items but also headings and more or less anything else really. I suppose especially in latex 2.09 without any extra packages, a messed up list construct was at least a plausible guess as to why latex was in this state, but the more constructs you define that are adding space with \addvspace the less likely it is that \item (or lack of \item) is the cause. –  David Carlisle Apr 1 '12 at 20:34
    
@DavidCarlisle thanks for the follow-up :) –  cmhughes Apr 2 '12 at 9:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.