2

Suppose I want to use enumerate within a \list. In my example, the first enumerate (before some text) works properly, but the second enumerate (after some text) does not. I would like to know why.

\documentclass[12pt]{article}
\usepackage{enumerate}

\newcounter{questioncounter}
\newenvironment{question}{% 
    \refstepcounter{questioncounter}
    \list{\thequestioncounter .}{%
        \item
}}{\endlist}

\begin{document}

\begin{question}

\begin{enumerate}[(i)]
\item enumerate 1, item 1 (OK)
\item enumerate 1, item 2 (OK)
\end{enumerate}

some text (OK)

\begin{enumerate}[(i)]
\item enumerate 2, item 1 (NOT OK)
\item enumerate 2, item 2 (NOT OK)
\end{enumerate}

\end{question}

\end{document}

enter image description here

3

enumerate, at least in its standard version from latex.ltx uses an \list internally too. The outer \list from the question environment` and the inner ones interfere, it's better to group them, to protect the list depth/enum depth counters.

I don't understand why an outer \list is used at all.

I've provided two ways -- with enumitem and its shortlabels option and the more sophisticated label=... approach.

Using enumitem with the indent/leftmargin features would provide a \list -less way, in my point of view.

\documentclass[12pt]{article}
\usepackage[shortlabels]{enumitem}


\newcounter{questioncounter}

\newenvironment{question}{% 
  \refstepcounter{questioncounter}
 \list{\thequestioncounter .}{%
 \item
   \begingroup
 }%
 \endgroup
}{\endlist}


\begin{document}

\begin{question}
  \begin{enumerate}[(i)]
  \item enumerate 1, item 1 (OK)
  \item enumerate 1, item 2 (OK)
  \end{enumerate}
  % Some text (OK)
  \begin{enumerate}[(i)]
  \item enumerate 2, item 1 (Now OK)
  \item enumerate 2, item 2 (Now OK)
  \end{enumerate}
\end{question}

With more sophisticated \verb!enumitem! - features

\begin{question}
  \begin{enumerate}[label={(\alph*)}]
  \item enumerate 1, item 1 (OK)
  \item enumerate 1, item 2 (OK)
  \end{enumerate}
  % Some text (OK)
  \begin{enumerate}[label={(\alph*)}]
  \item enumerate 2, item 1 (Now OK)
  \item enumerate 2, item 2 (Now OK)
  \end{enumerate}
\end{question}



\end{document}

enter image description here

  • The \begingroup and \endgroup tags in the question environment solved my question. As for why I used a \list - suppose I number the question 1 - 11. I wanted to use the questioncounter for these questions and be able to right align these question numbers. I'm not aware that this is possible using enumerate – nathanesau Sep 7 '15 at 15:38
  • @nathanesau: Please have a look into enumitem and it's alignment etc. features. – user31729 Sep 7 '15 at 16:54

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.