# Subitem in enumerate written as <item#>.<subitem#> instead of indentation

I want to define different requirements in my thesis, some of which can be divided into smaller requirements. Building on the answer to my previous question Referencing enumeration items by number and name, I came up with the following:

\documentclass{article}

\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{etoolbox}

\usepackage[showframe,pass]{geometry}

\begin{document}

\makeatletter
\newcommand*{\req}[1]{%
\item %
\let\originall@bel\@currentlabel%
\appto\@currentlabel{ (#1)}%
\newenvironment{subreqs}{\begin{enumerate}[label=\originall@bel.\arabic*,widest=9,leftmargin=0pt]}{\end{enumerate}}
\makeatother

\begin{enumerate}[label=R~\arabic*,widest*=20,leftmargin=*,series=reqs]
\req{First Important Thing} \label{req1} \lipsum[4]
\begin{subreqs}
\req{Important Subitem} \label{req2} \lipsum[2]
\end{subreqs}
\end{enumerate}

\ref{req1} and \ref{req2} are important.

\end{document}


This partly works as expected, the only problem is that the second requirement is indented with regard to the first one. This is of course expected since I use a second level of enumerate, but I'd still like to avoid it since the grouping is visible from the number itself.

Edit: I just realized that leftmargin (which I suspected to do something different) controls exactly what I want. However, using leftmargin=0pt instead of leftmargin=* in the definition of subreqs, as Thruston suggests does not really help, as it makes R 1.1 protrude out of the text frame (see the updated code/screenshot above).

• Try changing your subreqs environment to define leftmargin=0pt. Does this do what you want? – Thruston Nov 13 '13 at 12:10
• @Thruston: thanks for pointing this out, I thought that leftmargin only controlled the indentation of the wrapped lines following the item. However, setting it to 0pt does not really solve the problem either (see the updated question). – rainer Nov 13 '13 at 12:21

You should set leftmargin=0pt for the inner list. I suggest defining your own environment also for the outer list. There is no need for \originall@bel, but an \ignorespaces is needed.

\documentclass{article}

\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{etoolbox}

\newlist{reqs}{enumerate}{1}
\newlist{subreqs}{enumerate}{1}
\setlist[reqs]{label=R~\arabic*,widest*=100,leftmargin=*}
\setlist[subreqs]{label=\thereqsi.\arabic*,leftmargin=0pt}

\makeatletter
\newcommand*{\req}[1]{%
\item
\appto\@currentlabel{ (#1)}%
\makeatother

\begin{document}

\lipsum[3]
\begin{reqs}
\req{First Important Thing} \label{req1} \lipsum[4]
\begin{subreqs}
\req{Important Subitem} \label{req2} \lipsum[2]
\end{subreqs}
\end{reqs}
\lipsum[3]

\ref{req1} and \ref{req2} are important.

\end{document}


If you want left alignment of the labels, you can pass the label width of the outer environment to the inner one:

\documentclass{article}

\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{etoolbox}

\newlist{reqs}{enumerate}{1}
\newlist{subreqs}{enumerate}{1}
\setlist[reqs]{
label=R~\arabic*,
widest*=100,
leftmargin=*,
align=left,
before=\edef\outerlabelwidth{\the\labelwidth}
}
\setlist[subreqs]{
label=\thereqsi.\arabic*,
leftmargin=0pt,
labelindent=0pt,
labelwidth=\outerlabelwidth,
align=left,
}

\makeatletter
\newcommand*{\req}[1]{%
\item %
\appto\@currentlabel{ (#1)}%
\makeatother

\begin{document}

\lipsum[3]
\begin{reqs}
\req{First Important Thing} \label{req1} \lipsum[4]
\begin{subreqs}
\req{Important Subitem} \label{req2} \lipsum[2]
\end{subreqs}
\end{reqs}
\lipsum[3]

\ref{req1} and \ref{req2} are important.

\end{document}


• Thanks, this is nearly where I wanted it... I realize I'm nit-picking now, but is there any way to left-align the labels R 1 and R 1.1? I just played around with align=left, which seems to work for the first level of indentation, but moves the label of R 1.1 to the right if I add it in \setlist[subreqs]{...}. – rainer Nov 13 '13 at 12:52
• @rainer Left alignment added – egreg Nov 13 '13 at 13:07