0

I'd like to add arabic numbers to the custom environment described here:

Access optional item label when defining label style with enumitem

So to have this

\begin{enumerate}
    \item \emph{(Hello)} Lorem ipsum
    \item \emph{(World)} Dolor sit
\end{enumerate}

as the result of this:

\begin{named}
    \item[Hello] Lorem ipsum
    \item[World] Dolor sit
\end{named}

Varying on the solution of the linked question doesn't fully work because this

\newlist{named}{enumerate}{3}
\newcommand\parens[1]{(#1)}
\setlist[named]{
  label=\arabic*,
  font=\itshape\parens,
}

Doesn't show numbers and has a weird alignment (I'd like to have the same alignment as in the description environment).

1 Answer 1

1

How about this:

\documentclass{article}
\usepackage{enumitem}
\newlist{named}{enumerate}{3}
\setlist[named]{
  label=\arabic*,
  labelsep=*,
}
\newcommand*\nameditem[1][]{%
  \item \hspace{-1em}\mbox{\itshape#1}%
}
\usepackage{microtype}
\frenchspacing

\begin{document}
\begin{named}
  \nameditem[Hello] Lorem ipsum dolor sit amet, consectetuer
    adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi
    et neque pharetra sollicitudin.
  \nameditem[World] Lorem ipsum dolor sit amet, consectetuer
    adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi
    et neque pharetra sollicitudin.
  \nameditem Lorem ipsum dolor sit amet, consectetuer
    adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi
    et neque pharetra sollicitudin.
\end{named}

\begin{description}
  \item[Hello] Lorem ipsum dolor sit amet, consectetuer
    adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi
    et neque pharetra sollicitudin.
  \item[World] Lorem ipsum dolor sit amet, consectetuer
    adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi
    et neque pharetra sollicitudin.
  \item Lorem ipsum dolor sit amet, consectetuer
    adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi
    et neque pharetra sollicitudin.
\end{description}
\end{document}

lists

I’m going to ignore the “ugly” space in the last item of the description list (it is supposed to have a [description] anyway).

2
  • Very clever! But it seems strange I can't achieve it with just plain $\item$. Just for curiosity, what is labelsep for?
    – seldon
    Aug 29, 2018 at 7:12
  • @mattecapu The length \labelsep is not very intuitive: You can find a visual representation in Section 3.3 of the enumitem manual. The key-value setup labelsep=* is described in the first paragraph of page 5. Aug 29, 2018 at 14:52

You must log in to answer this question.

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