4

I have a class file in which I need to set up the enumerate and the inline version enumerate* (as provided by the enumitem package with option inline). As defined, the two environments share labels, settings, etc.

I want them to be able to share levels (i.e. an enumerate* environment nested inside an enumerate environment is recognised to be at level 2), but I need to be able to adjust the formatting on the enumerate* environment (among other adjustments, I want this to start on a new line).

The problem is that I can't change enumerate* (e.g. using \setlist) without also changing enumerate. I can get around that by using (e.g.) \renewlist{enumerate*}{enumerate*}{3}, but then the nesting gets lost.

Here is a MWE:

\documentclass{article}
\usepackage[inline]{enumitem}

\setlist[enumerate]{align=left,leftmargin=8mm,labelsep*=0pt}
\setlist[enumerate,1]{label=(\alph*), ref=(\alph*)}
\setlist[enumerate,2]{label=(\roman*), ref=(\roman*),leftmargin=9mm}

\begin{document}

Here's a non-nested inline enumerate list:
\begin{enumerate*}
  \item blah
  \item blah
  \item blah
\end{enumerate*}

\begin{enumerate}
  \item blah
  \item Here's a nested inline list:
  \begin{enumerate*}
    \item blah
    \item blah
    \item blah
  \end{enumerate*}
\end{enumerate}

\end{document}

In this MWE, the challenge is to modify the preamble in order for both inline lists to start on a new line, but for the nested one to use \roman* labelling, while the non-nested ones uses \alph*.

Bonus points if you can do it entirely within enumitem, as the users of the class file would like to have features such as [resume] available.

  • Do you mean something like \newenvironment{inumerate}{\par\begin{enumerate*}}{\end{enumerate*}} with the usage \begin{enumerate} \item blah \item Here's a nested inline list: \begin{inumerate} \item blah \item blah \item blah \end{inumerate} \end{enumerate} ? – Steven B. Segletes Oct 13 '17 at 14:29
  • That would add a new blank line, yes, but there are a few other tweaks (which I didn't mention, sorry) that need to be made to the enumerate* environment. The following gives the formatting I want, but doesn't respect the levels: \renewlist{enumerate*}{enumerate*}{3} followed by \setlist*[enumerate*]{before=\vspace{6pt}\newline,itemjoin=\hspace{50pt}} – rbrignall Oct 13 '17 at 14:33
  • Well, I can't get your code to compile (LaTeX Error: There's no line here to end.) But note that in my approach, you can , inside of inumerate, temporarily redefine the enumerate* environment with the optional argument. That is, \newenvironment{inumerate}{\begin{enumerate*}[before=\vspace{6pt}\newline,itemjoin=\hspace{50pt}]}{\end{enumerate*}} – Steven B. Segletes Oct 13 '17 at 14:44
  • Strange. It compiles for me, both in TeXLive (on a Mac) and MiKTeX (on Windows)... I take your point that optional arguments can be passed through - a nice feature. – rbrignall Oct 13 '17 at 14:48
  • Sometimes copy/paste introduces non-visible junk that screw things up. I just instead posted an answer that may possibly give an approach. – Steven B. Segletes Oct 13 '17 at 14:52
2

Rather than try to exchange code via comments, I thought I would just post what I have.

Here, I introduce the inumerate environment that is an inline enumerate* variety that modifies certain parameters of the enumeration that the OP seemed interested in.

\documentclass{article}
\usepackage[inline]{enumitem}

\setlist[enumerate]{align=left,leftmargin=8mm,labelsep*=0pt}
\setlist[enumerate,1]{label=(\alph*), ref=(\alph*)}
\setlist[enumerate,2]{label=(\roman*), ref=(\roman*),leftmargin=9mm}
\newenvironment{inumerate}{\begin{enumerate*}[before=\vspace{6pt}\newline,
  itemjoin=\hspace{50pt}]}{\end{enumerate*}}
\begin{document}

Here's a non-nested inline enumerate list:
\begin{inumerate}
  \item blah
  \item blah
  \item blah
\end{inumerate}

\begin{enumerate}
  \item blah
  \item Here's a nested inline list:
  \begin{inumerate}
    \item blah
    \item blah
    \item blah
  \end{inumerate}
  \item Next outer item
\end{enumerate}
\end{document}

enter image description here

The above does not support resume because inumerate, being an environment, is grouped, and the data necessary to resume are lost. Here I instead provide a pseudo-environment xnumerate that will support resume.

I also provide the original inumerate environment, modified to take additional optional arguments (except resume).

\documentclass{article}
\usepackage[inline]{enumitem}

\setlist[enumerate]{align=left,leftmargin=8mm,labelsep*=0pt}
\setlist[enumerate,1]{label=(\alph*), ref=(\alph*)}
\setlist[enumerate,2]{label=(\roman*), ref=(\roman*),leftmargin=9mm}
\newenvironment{inumerate}[1][]{\begin{enumerate*}[before=\vspace{6pt}\newline,
  itemjoin=\hspace{50pt},#1]}{\end{enumerate*}}
  \newcommand\xnumerate[1][]{\xnumerateaux{#1}}
\def\xnumerateaux#1#2\endxnumerate{\begin{enumerate*}[before=\vspace{6pt}\newline,
  itemjoin=\hspace{50pt},#1]#2\end{enumerate*}}
\begin{document}

Here's a non-nested inline enumerate list:
\begin{inumerate}
  \item blah
  \item blah
  \item blah
\end{inumerate}

\begin{enumerate}
  \item blah
  \item Here's a nested inline list:
  \xnumerate
    \item blah
    \item blah
    \item blah
  \endxnumerate
  \item Next outer item
  \xnumerate[resume]
    \item blah
    \item blah
    \item blah
  \endxnumerate
  \item Next outer item
\end{enumerate}
\end{document}

enter image description here

  • I like this. I can add [1][] into the environment definition to pass enumitem parameters through to enumerate*. There's just one issue (possibly not something that's ever needed to be done, but all suggestions welcome): [resume] doesn't work, presumably because enumitem doesn't understand what its resuming... – rbrignall Oct 13 '17 at 15:04
  • @RobertBrignall I am thinking that is because inumerate creates its own group and so the data necessary to perform the resume is lost upon exit from inumerate. – Steven B. Segletes Oct 13 '17 at 15:08
  • @RobertBrignall See my addendum. – Steven B. Segletes Oct 13 '17 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.