# Creating a list style with enumitem

I know it's possible with the enumitem package, to modify the list label to a custom format. I've hacked together solutions to a couple of other questions I found on StackExchange to give me the 'solution' below. Whilst it's the output I want, the code in the preamble is not very concise.

Is it possible do the same thing (or similar) using only the \newlist and \setlist commands from enumitem (and any other commands from enumitem I might need)?

\documentclass[a4paper,10pt]{article}

\usepackage{enumitem}

\newcommand{\changeitem}{%
\let\latexitem\item
\renewcommand\item[1][]{\latexitem\relax{##1 --} }%
}

\newlist{steps}{enumerate}{1}
\setlist[steps]{label=\textit{Step \arabic*:},leftmargin=*}

\newenvironment{labelledsteps}[1][]
{\begin{steps}[before=\changeitem,#1]}
{\end{steps}}

\begin{document}

\begin{labelledsteps}
\item[First Label]  First list item \newline
Still first list item
\item[Second Label] Second list item
\item[Third Label]  Third list item
\end{labelledsteps}

\end{document}

• You should consider placing \let\latexitem\item in the preamble outside of the \changeitem macro. That way, \changeitem will operate each time on the standard LaTeX \item. As you have formulated it, each new \changeitem will be relative to the current definition of \item. – Steven B. Segletes Apr 3 '15 at 15:20
• Why don't you just start from scratch? All you need is \hangindent, \makebox and a counter. – John Kormylo Apr 3 '15 at 15:23
• I don't understand what the labelledsteps does with respect to steps, nor \changeitem, apart from adding an endash after t he label, which it would be as simple doing by hand and the label as ordinary text. Or do I miss something? – Bernard Apr 3 '15 at 15:30
• Yes @Bernard, it is! I could do it manually, but for readability before compiling I think it's better to have it as a label. Both the answers posted certainly give me the flexibility I was after. Before I accept one though I would like to check that it actually is that case that this flexibility isn't present in the enumitem package then? Specifically, I can't have a #1 typed argument in the \setlist command when I'm setting the label text? – Jack B Apr 4 '15 at 15:58
• I thought of such a solution but didn't see how to do it. – Bernard Apr 4 '15 at 16:37

How about this code, using xparse and, incidentally, xspace:

\documentclass[a4paper,10pt]{article}

\usepackage{enumitem}
\usepackage{xspace}
\usepackage{xparse}
\DeclareDocumentCommand\newstep{o}{%
\item\IfNoValueTF{#1}{}{#1 \textendash\xspace}}

\newlist{steps}{enumerate}{1}
\setlist[steps]{label=\textit{Step \arabic*:},leftmargin=*}

\begin{document}

\begin{steps}
\newstep[First Label] First list item \newline
Still first list item
\newstep[Second Label] Second list item
\newstep[Third Label] Third list item
\newstep A Fourth list item without a label.
\end{steps}

\end{document}


Here is an alternative using no packages. The upside is that there is nothing you can't change. The downside is that it is only one layer deep (no subitems).

\documentclass[a4paper,10pt]{article}

\newcounter{steps}

\newcommand{\step}[1][\empty]% #1 = label (optional)
{\stepcounter{steps}%
\par
\hangindent=4em
\hangafter=1
\makebox[4em][l]{\textit{Step \arabic{steps}:}}%
\ifx#1\empty\else #1 --\fi
}
\newenvironment{labelledsteps}%
{\setcounter{steps}{0}%
\let\item=\step
\parskip=\baselineskip
\parindent=0pt}%
{\par}

\begin{document}

\begin{labelledsteps}
\item[First Label]  First list item \newline
Still first list item
\item[Second Label] Second list item
\item[Third Label]  Third list item
\item No label
\end{labelledsteps}

\end{document}


Same output in a simple way without using newlist and setlist of course:

\documentclass[a4paper,10pt]{article}

\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=\textit{Step \arabic*:}]
\item First list item \newline
Still first list item
\item Second list item
\item Third list item
\item A Fourth list item without a label.
\end{enumerate}

\end{document}