I have an enumerate
environment that I want to refer to later in my document using \ref
and \label
, but enumerate
doesn't get numbered by section (the way, say, figure
would). How can I add section numbers to enumerate
?
I do not want individual, enumerated items to be numbered. Rather, I want the enumeration as a whole to be numbered.
What I am really looking for is something like this:
Algorithm 1.2
2. Buy Milk
3. Walk Home
… /snip/ …
As described in Algorithm 1.2, it's easy to buy milk.
I don't want to use a figure because I can't have it moving around the document. I don't want to use the theorem/definition/proof environments because of all the styling. The algorithm environments use a lot of styling too. I'm basically looking for a way to slap a title on my enumerate environment and give it a number that I can refer to.
Edit:
This is what I finally ended up with, based on Mico's post:
\usepackage{amsmath}
\newcounter{algcounter}
\newenvironment{alg}{
\bigskip\noindent
\refstepcounter{algcounter}
\textbf{Algorithm \thealgcounter}
\newline
\begin{enumerate}
\setlength{\itemsep}{1pt}
\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}
}{\end{enumerate}}
\numberwithin{algcounter}{section}
Best Answer
If you're willing to load the
amsmath
package (you may be doing so already anyway...), you can just issue the commandto have level-1 enumerations be subordinated to the section.
Addendum. From your follow-up remarks, it would appear that you're not trying to change the appearance of LaTeX's own
enumerate
environment but, instead, want to create a custom environment that will be numbered within sections. (I.e., each time a\section
command is encountered, numbering should start over at "1"; however, the section number needs to be prefixed to the environment number.) The following MWE illustrates how this may be achieved.