[Tex/LaTex] Format reference to items in nested list with cleveref

#enumeratecleverefcross-referencingformattinglists

I'm using the cleveref package to format references in my documents. However I am having difficulties implementing different formats for labels referring to enumerate-lists, in particular nested list.

Here is a minimal example:

\documentclass{article}

\usepackage{enumerate}
\usepackage{cleveref}

\creflabelformat{enumi}{#1(#2)#3}
\creflabelformat{enumii}{#1(#2)#3}


\begin{document}

\begin{enumerate}[(i)]
  \item\label{fi} The first item
  \item the second item
  \begin{enumerate}[(a)]
    \item the first sub-item
    \item\label{ssi} the second sub-item
  \end{enumerate}
\end{enumerate}

This is a fancy reference to the first item: \labelcref{fi}.

The second sub-item can be referred to as \labelcref{ssi}.

\end{document}

Ideally, I would like the first reference to be formatted as (i), and the second as (ii-b).

The actual output is the following:
enter image description here

As we can see, both labels look different, i() instead of (i); and iib instead of (b) [I don't how to use `creflabelformat to get (ii-b), so I went for (b) but even this doesn't work.]

I know there are a few questions, some recent, asking about formatting references to list items, but they didn't really help me.

Many thanks.

Best Answer

You can use the label, ref keys from the enumitem package to control the format for the labels and the references (I added some settings for the third and fourth nesting levels just as an illustration):

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

\setlist[enumerate,1]{label=(\roman*),ref=(\roman*)}
\setlist[enumerate,2]{label=(\alph*),ref=(\roman{enumi}-\alph*)}
\setlist[enumerate,3]{label=(\Alph*),ref=(\roman{enumi}-\alph{enumii}-\Alph*)}
\setlist[enumerate,4]{label=(\arabic*),ref=(\roman{enumi}-\alph{enumii}-\Alph{enumiii}-\arabic*)}

\begin{document}

\begin{enumerate}
  \item\label{fi} The first item
  \item the second item
  \begin{enumerate}
    \item the first sub-item
    \item\label{ssi} the second sub-item
    \begin{enumerate}
      \item\label{fssi} the first subsub-item
        \begin{enumerate}
          \item the first subsubsub-item
          \item\label{ssssi} the second subsubsub-item
        \end{enumerate}
      \item the second subsub-item
    \end{enumerate}
  \end{enumerate}
\end{enumerate}

This is a fancy reference to the first item: \cref{fi}.

The second sub-item can be referred to as \cref{ssi}.

The second subsub-item can be referred to as \cref{fssi}.

The second subsubsub-item can be referred to as \cref{ssssi}.

\end{document}

enter image description here