3

This question is actually based on a modified version of this answer. The original solution works perfectly well.

However, I wanted to add the word Case before the number and a comma after the number. While the word before the number works, a comma after the number throws an error which I have failed to solve.

Here is the modified source:

\documentclass{scrbook}

\usepackage{enumitem}
\newcounter{descriptcount}
\newlist{enumdescript}{description}{1}
\setlist[enumdescript,1]{%
  before={\setcounter{descriptcount}{0}%
          \renewcommand*\thedescriptcount{\arabic{descriptcount}}},
        font=\bfseries\stepcounter{descriptcount}Case \thedescriptcount,~
}

\begin{document}

\begin{enumdescript}
   \item item one
   \item item two
   \item[Some Text] item three
   \item item four
   \item item five
\end{enumdescript}
\end{document}

This generates an error,

! Missing \endcsname inserted.
<to be read again> 
                   \protect 
l.15    \item
              item one
?

If the comma after \thedescriptcount is removed, it will work perfectly.

Masroor
  • 17,842

1 Answers1

2

The setting font=\bfseries\stepcounter{descriptcount}Case \thedescriptcount, will lead to the typesetting as requested, but the , should be a part of the typesetting, not being handled as separator of the key-value interface. Omitting a {} pair around this leads to a ~ as a key, which is not understood by enumitem.

\documentclass{scrbook}

\usepackage{enumitem}
\newcounter{descriptcount}
\newlist{enumdescript}{description}{1}
\setlist[enumdescript,1]{%
  before={\setcounter{descriptcount}{0}%
          \renewcommand*\thedescriptcount{\arabic{descriptcount}}},
        font={\bfseries\stepcounter{descriptcount}Case \thedescriptcount,~}
}

\begin{document}

\begin{enumdescript}
   \item item one
   \item item two
   \item[Some Text] item three
   \item item four
   \item item five
\end{enumdescript}
\end{document}

enter image description here