0

I've been playing with this pretty ToC, with the goal of simplifying it for my needs. I have successfully done that, but when I try to implement it into my bigger file, \frontmatter seems to cause an error, yet the code runs error-free without \frontmatter.

The error produced, is:

! 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}

There is no missing } in the code, so there is some deeper issue. I've been researching this error but don't understand how to fix it.

MWE:

\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}
AML
  • 2,265

1 Answers1

2

With frontmatter the chapter is unnumbered. The argument of titlecontents is empty and so you end with an lonely \endleftbar which hasn't a opening \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}

enter image description here

Ulrike Fischer
  • 327,261