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.

I want to use the \crefname macro from the cleveref package to set the label names on several layers of an enumerate environment. The following code works very well:

\documentclass{article}
\usepackage{forloop}
\usepackage{cleveref}

\newcounter{ct}\forloop{ct}{1}%
    {\value{ct}<10}
    {\crefname{enum\roman{ct}}{case}{cases}}

\begin{document}
\begin{enumerate}
\item \label{l} test
\begin{enumerate}
\item test 
\item \label{k} test
\end{enumerate}
\end{enumerate}

\cref{l,k}

\end{document}

However, it stops working when I use the enumitem package:

\documentclass{article}
\usepackage{forloop}
\usepackage{enumitem}
\usepackage{cleveref}

\newlist{test}{enumerate}{10}
\setlist[test]{label=\arabic*}

\newcounter{ct}\forloop{ct}{1}%
    {\value{ct}<10}
    {\crefname{test\roman{ct}}{case}{cases}}

\begin{document}
\begin{test}
\item \label{l} test
\begin{test}
\item test 
\item \label{k} test
\end{test}
\end{test}

\cref{l,k}

\end{document}

You can check that adding \crefname{testi}{case}{cases} will indeed make the first reference label correctly, so I have no idea why this is not working. It'd be great if someone could tell me what is going wrong and how to fix it.

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

I really don't know why the thing works for enumi and so on, but it's decidedly a bad idea to give them a \crefname globally.

You're looking for "aliasing" the testii, testiii, … counter reference to testi, I believe:

\documentclass{article}
\usepackage{enumitem}
\usepackage{cleveref}

\newlist{test}{enumerate}{10}
\setlist[test]{label*=.\arabic*}
\setlist[test,1]{label=\arabic*}
\crefname{testi}{case}{cases}    

% alias testii, testiii, ... to testi
\count255=1
\loop\ifnum\count255<10
  \advance\count255 1
  \crefalias{test\romannumeral\count255}{testi}    
\repeat

\begin{document}
\begin{test}
\item \label{l} test
\begin{test}
\item test
\item \label{k} test
\end{test}
\end{test}

\cref{l,k}

\end{document}

Feel free to use a different loop macro, I'm not familiar with forloop.

I've modified the list counters, as it would be unclear which level you're referring to.

enter image description here

share|improve this answer
    
Perfect! Thanks a bunch, this finally settles an ancient LaTeX battle for me. –  Jesko Hüttenhain Mar 7 '13 at 18:56
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.