4

I am using the enumitem package with the following custom list:

\newlist{answers}{enumerate}{2}
\setlist[answers,1]{label=(\alph*), ref=(\alph*)}
\setlist[answers,2]{label=(\roman*), ref=(\alph{answersi}.\roman*)}

Its purpose is to list answers to questions on assessments. I similarly have one for answers. It is often used to write nested questions, such as:

Here are my answers:

\begin{answers} \item First answer \item Second answers: \begin{answers}[series=innerlist] \item Answer Two-One \item Answer Two-Two \end{answers} \end{answers}

Something I need to exit for

\begin{answers}[resume, start=2] \item \begin{answers}[resume=innerlist] \item Answer Two-Three \item Answer Two-Four \end{answers} \item Answer Three \end{answers}

I want my resumed outer list to resume from (b), as it does, but without showing the label, so that it looks as though the list never broke, and the inner list continues as normal. I thought using \item[] would do, however, although that hides that item's label, it then continues with the next item being (b), rather than (c).

Can this be done? I have not been able to find any posts on this situation, nor have I found anything in the enumitem manual.

Edit: I forgot to mention that I'm aware I could do this in the resuming of the environments:

\begin{answers}
    \item[] \begin{answers}[resume=innerlist]
        \item Answer Two-Three
        \item Answer Two-Four
    \end{answers}
    \setcounter{answersi}{2}
    \item Answer Three
\end{answers}

Is this the only way/preferred way, or is there a way to use the environment options, instead?

Mico
  • 506,678
  • 1
    I can think of a slight simplification: If you replace the first instance of \begin{answers} in the lower code block with \begin{answers}[resume], you wouldn't need the instruction \setcounter{answersi}{2} later on. – Mico May 13 '23 at 08:00
  • I'm curious about "Something which I need to exit for." In exam class it uses \fullwidth to temporarily suspend the indentations (see https://tex.stackexchange.com/questions/596449/why-is-the-caption-not-centered-in-an-exercise-question). – John Kormylo May 13 '23 at 12:04
  • @Mico Yeah, I must have made an error in my trials, because I am certain it didn't work before. – TimeTravelPenguin May 13 '23 at 13:16
  • @JohnKormylo In my case, there are times when I need to exit because I need to do something that doesn't behave in the environment. An example, though I avoid it as much as possible, is using floats. That link you included is actually interesting, and I haven't seen that before. Thanks for the info! It is helpful. – TimeTravelPenguin May 13 '23 at 13:19

1 Answers1

5

To correctly resume both, the inner and the outer list, you should also name the series of the outer list:

\documentclass{article}

\usepackage{enumitem} \newlist{answers}{enumerate}{2} \setlist[answers,1]{label=(\alph), ref=(\alph)} \setlist[answers,2]{label=(\roman), ref=(\alph{answersi}.\roman)}

\begin{document} Here are my answers:

\begin{answers}[series=outerlist] \item First answer \item Second answers: \begin{answers}[series=innerlist] \item Answer Two-One \item Answer Two-Two \end{answers} \end{answers}

Something I need to exit for

\begin{answers}[resume=outerlist] \item[]\begin{answers}[resume=innerlist] \item Answer Two-Three \item Answer Two-Four \end{answers} \item Answer Three \end{answers}

\end{document}

enter image description here

In your case, it even would work without naming the outer list, only using start together with resume does not make much sense (example extended to not have the same counter value for resuming the inner and outer list):

\documentclass{article}

\usepackage{enumitem} \newlist{answers}{enumerate}{2} \setlist[answers,1]{label=(\alph), ref=(\alph)} \setlist[answers,2]{label=(\roman), ref=(\alph{answersi}.\roman)}

\begin{document} Here are my answers:

\begin{answers} \item First answer \item Second answers: \begin{answers}[series=innerlist] \item Answer Two-One \item Answer Two-Two \item Answer Two-Three \item Answer Two-Four \end{answers} \end{answers}

Something I need to exit for

\begin{answers}[resume] \item[]\begin{answers}[resume=innerlist] \item Answer Two-Five \item Answer Two-Six \end{answers} \item Answer Three \end{answers}

\end{document}

enter image description here

However, if you prefere to use a start value, use the correct one. So if the first automatic numbered item should be c use 3 (as it is the third letter in the alphabet):

\documentclass{article}

\usepackage{enumitem} \newlist{answers}{enumerate}{2} \setlist[answers,1]{label=(\alph), ref=(\alph)} \setlist[answers,2]{label=(\roman), ref=(\alph{answersi}.\roman)}

\begin{document} Here are my answers:

\begin{answers} \item First answer \item Second answers: \begin{answers}[series=innerlist] \item Answer Two-One \item Answer Two-Two \end{answers} \end{answers}

Something I need to exit for

\begin{answers}[start=3] \item[]\begin{answers}[resume=innerlist] \item Answer Two-Three \item Answer Two-Four \end{answers} \item Answer Three \end{answers}

\end{document}

The result is the same as shown for the first example.

cabohah
  • 11,455
  • Oh jeez, I must have messed up because I am certain I tried this and it wasn't behaving as it does now. Thanks for the extensive response. I am very grateful! – TimeTravelPenguin May 13 '23 at 13:15