[Tex/LaTex] Subitem in enumerate written as . instead of indentation

#enumerateindentation

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)}%
  \emph{#1}\quad}
\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.

enter image description here

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).

Best Answer

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)}%
  \emph{#1}\quad\ignorespaces}% <--- note \ignorespaces
\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}

enter image description here

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)}%
  \emph{#1}\quad\ignorespaces}
\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}

enter image description here