4

How can I adapt a sorted list so that it becomes an enumerated sorted list? Here is the sorted list I currently have.

\documentclass{report}
\usepackage{enumitem}
\usepackage{datatool}

\newcommand{\sortitem}[2]{%
\DTLnewrow{list}%
\DTLnewdbentry{list}{label}{#1}%
\DTLnewdbentry{list}{description}{#2}%
}

\newenvironment{sortedlist}{%
\DTLifdbexists{list}{\DTLcleardb{list}}{\DTLnewdb{list}}%
}{%
\DTLsort{label}{list}%
\begin{description}%
\DTLforeach*{list}{\theLabel=label,\theDesc=description}{%
\item[\theLabel] \theDesc }%
\end{description}%
}

\section*{Analysis.}
\begin{sortedlist}
\sortitem{Elementary Analysis--The Theory of Calculus}{Ross}
\sortitem{Analysis of Functions of a Single Variable}{Baggett}
\sortitem{Advanced Calculus and Real Analysis}{Craw}
\end{sortitem}

\end{document}

I would like for this list to be an enumerated list as well. Is that possible, and if so how?

1 Answer 1

4

Just use an enumerated list rather than a description:

enter image description here

\documentclass{article}
\usepackage{enumitem,datatool}% http://ctan.org/pkg/{enumitem,datatool}

\newcommand{\sortitem}[2]{%
  \DTLnewrow{list}%
  \DTLnewdbentry{list}{label}{#1}%
  \DTLnewdbentry{list}{description}{#2}%
}

\newenvironment{sortedlist}
  {% \begin{sortedlist}
  \DTLifdbexists{list}{\DTLcleardb{list}}{\DTLnewdb{list}}%
  }{% \end{sortedlist}
  \DTLsort{label}{list}%
  \begin{enumerate}%
    \DTLforeach*{list}{\theLabel=label,\theDesc=description}{%
      \item \textbf{\theLabel} \theDesc}%
  \end{enumerate}%
  }

\begin{document}
\section*{Analysis.}
\begin{sortedlist}
  \sortitem{Elementary Analysis--The Theory of Calculus}{Ross}
  \sortitem{Analysis of Functions of a Single Variable}{Baggett}
  \sortitem{Advanced Calculus and Real Analysis}{Craw}
\end{sortedlist}

\end{document}

Since you're loading enumitem, you can insert your list settings as part of the enumerate environment options.

1
  • Great and thanks! That is exactly what I was looking for. Commented Aug 23, 2012 at 1:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .