3

I get an toc error when I use the tcolorbox for getting a grey background in the contentline of the Parts. Despite the error, the pdf is created correctly.

Undefined control sequence. \contentsline {part}{I\hspace {1em}Part1}{3}
Undefined control sequence. \contentsline {part}{II\hspace {1em}Part2}{7}
\documentclass[12pt,a4paper,openright,twoside]{book}
\usepackage[english]{babel}
\usepackage{tcolorbox}

\makeatletter
\renewcommand*\l@part[2]{%
    \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \setlength\@tempdima{3em}%
    \begingroup
    \parindent \z@ \rightskip \@pnumwidth
    \parfillskip -\@pnumwidth
    \begin{tcolorbox}[colback=black!10, right=0.5ex, left=0cm, arc=0pt,outer arc=0pt, boxrule=0mm, width=1.01\textwidth]
        {\leavevmode
            \large \bfseries \vbox{\sffamily\bfseries#1}%
            \hb@[email protected]{\hss #2}
        }
    \end{tcolorbox}
    \vspace*{.5ex}
    \nobreak
    \global\@nobreaktrue
    \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
    \fi}
\makeatother


\begin{document}
    \tableofcontents
    \part{Part1}
    \chapter{Chapter1}

    \part{Part2}
    \chapter{Chapter2}
\end{document}

The file list of my log is.

*File List*
    book.cls    2014/09/29 v1.4h Standard LaTeX document class
    bk12.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
   babel.sty    2014/09/25 3.9l The Babel package
 bblopts.cfg    2006/07/31 v1.0 MiKTeX 'babel' configuration
 english.ldf    2012/08/20 v3.3p English support from the babel system
tcolorbox.sty    2015/07/16 version 3.70 text color boxes
     pgf.sty    2013/12/18 v3.0.0 (rcs-revision 1.14)
  pgfrcs.sty    2013/12/20 v3.0.0 (rcs-revision 1.28)
everyshi.sty    2001/05/15 v3.00 EveryShipout Package (MS)
  pgfrcs.code.tex
 pgfcore.sty    2010/04/11 v3.0.0 (rcs-revision 1.7)
graphicx.sty    2014/10/28 v1.0g Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
graphics.sty    2014/10/28 v1.0p Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2007/01/18 v1.5 graphics configuration of teTeX/TeXLive
  pdftex.def    2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
 ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
  pgfsys.sty    2013/11/30 v3.0.0 (rcs-revision 1.47)
  pgfsys.code.tex
pgfsyssoftpath.code.tex    2013/09/09  (rcs-revision 1.9)
pgfsysprotocol.code.tex    2006/10/16  (rcs-revision 1.4)
  xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
 pgfcore.code.tex
pgfcomp-version-0-65.sty    2007/07/03 v3.0.0 (rcs-revision 1.7)
pgfcomp-version-1-18.sty    2007/07/23 v3.0.0 (rcs-revision 1.1)
verbatim.sty    2014/10/28 v1.5q LaTeX2e package for verbatim enhancements
 environ.sty    2014/05/04 v0.3 A new way to define environments
trimspaces.sty    2009/09/17 v1.1 Trim spaces around a token list
etoolbox.sty    2015/05/04 v2.2 e-TeX tools for LaTeX (JAW)
supp-pdf.mkii
 ***********
11
  • 1
    I have no problem with an up-to-date TL 2015
    – user2478
    Commented Jul 28, 2015 at 15:56
  • @PierPaolo: there is no \else. It is \ifnum ... \fi
    – user2478
    Commented Jul 28, 2015 at 15:58
  • Where I must put the \else?
    – Xeo
    Commented Jul 28, 2015 at 16:01
  • No errors here (TeX Live2015). Did you try deleting the auxiliary files and recompiling? Commented Jul 28, 2015 at 16:11
  • 1
    There is a bug in 2015/07/16 version 3.70 of tcolorbox. Updating to 2015/07/23 version 3.71 solves the problem. Commented Jul 29, 2015 at 6:20

1 Answer 1

2

This is not the answer to the question (Thomas F. Sturm already stated that there was a bug in 3.70 of tcolorbox), but I wanted to suggest to use a separate newtcolorbox for this \l@part command -- it can be changed easier then:

\documentclass[12pt,a4paper,openright,twoside]{book}
\usepackage[english]{babel}
\usepackage[most]{tcolorbox}

\newtcolorbox{lpartbgbox}{%
  colback=yellow, right=0.5ex, left=0cm, arc=0pt,outer arc=0pt, boxrule=0mm, width=1.01\textwidth
}%

\makeatletter
\renewcommand*\l@part[2]{%
    \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \setlength\@tempdima{3em}%
    \begingroup
    \parindent \z@ \rightskip \@pnumwidth
    \parfillskip -\@pnumwidth
    \begin{lpartbgbox}
        {\leavevmode
            \large \bfseries \vbox{\sffamily\bfseries#1}%
            \hb@[email protected]{\hss #2}
        }
    \end{lpartbgbox}
    \vspace*{.5ex}
    \nobreak
    \global\@nobreaktrue
    \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
    \fi}
\makeatother


\begin{document}
    \tableofcontents
    \part{Part1}
    \chapter{Chapter1}

    \part{Part2}
    \chapter{Chapter2}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .