Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Great and thanks! That is exactly what I was looking for. –  Michael Dykes Aug 23 '12 at 1:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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