mardi 2 décembre 2014

Nested List with Counters and Flush-Left Labels


Presently, I accomplish this with a combination of three user-defined lists. Two of these (examlist for single-digit labels, and exxamlist for double-digit labels) control the top-level items. The third (examlistii) controls the sub-level items for both of the top-level cases.


The effect (as demonstrated below) is precisely what I want. The means, though, seems barbaric. I'd like to accomplish this using a "single" list, perhaps using the 'enumitem' package, but I can't seem to turn the trick with the list keys. Any assistance would be appreciated.



\documentclass{article}

%examlist
\newcounter{exami}
\newenvironment{examlist}
{\begin{list}{\arabic{exami}.\hfill}
{\usecounter{exami}
\setlength{\labelwidth}{3ex}
\setlength{\labelsep}{0ex}
\setlength{\leftmargin}{3ex}}}
{\end{list}}

%exxamlist
\newcounter{exxam}
\newenvironment{exxamlist}
{\begin{list}{\arabic{exxam}.\hfill}
{\usecounter{exxam}\setcounter{exxam}{9}
\setlength{\labelwidth}{4.2ex}
\setlength{\labelsep}{0ex}
\setlength{\leftmargin}{4.2ex}}}
{\end{list}}

%examlistii
\newcounter{examii}
\newenvironment{examlistii}
{\begin{list}{\alph{examii})\hfill}
{\usecounter{examii}
\setlength{\labelwidth}{3ex}
\setlength{\labelsep}{0ex}
\setlength{\leftmargin}{3ex}}}
{\end{list}}

\begin{document}
\noindent
This is the surrounding text. The following list has flush-left labels.

\begin{examlist}
\item Problem 1
\item Problem 2

\begin{examlistii}
\item Part (a)
\item Part (b)
\end{examlistii}

\item Problem 3
\end{examlist}

\begin{exxamlist}
\item Problem 10

\begin{examlistii}
\item Part (a)
\item Part (b)
\end{examlistii}

\item Problem 11
\end{exxamlist}
\end{document}




Aucun commentaire:

Enregistrer un commentaire