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

  • 1. Walk to store.
    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.


    This is what I finally ended up with, based on Mico's post:

    \textbf{Algorithm \thealgcounter}
    • 4
      Next time, please state your full requirements at the start. That'll save potential helpers some work.
      – lockstep
      Feb 5, 2012 at 15:39
    • Can you elaborate why you don't want to use a theorem environment. I think what you are asking is a specific type of a theorem. It is relatively easy to change the style of theorem, for example, by using the ntheorem package.
      – Aditya
      Feb 5, 2012 at 15:44
    • 1
      @Jake: Do you want to use the algorightm-environment. Please provide a minimal example. Feb 5, 2012 at 16:06
    • 2
      @MarcoDaniel: I see your first name is being (mis)spelled as "Macro". Welcome to the club -- my first name frequently gets misspelled "Micro".
      – Mico
      Feb 5, 2012 at 18:38
    • 1
      @Mico: We have difficult names ;-) Feb 5, 2012 at 19:03

    2 Answers 2


    If you're willing to load the amsmath package (you may be doing so already anyway...), you can just issue the command


    to 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.

    \usepackage{amsmath} % needed for its \numberwithin command
    \newenvironment{myalg}{%      define a custom environment
       \bigskip\noindent%         create a vertical offset to previous material
       \refstepcounter{myalgctr}% increment the environment's counter
       \textsc{Algorithm \themyalgctr}% or \textbf, \textit, ...
       }{\par\bigskip}  %          create a vertical offset to following material
    \section{First section}
    Some text before the first algorithm environment \ldots
    Some thoughts\ldots \label{alg:first}
    More thoughts\ldots \label{alg:second}
    Some text after the second algorithm environment \ldots
    \section{Second section}
    Further thoughts\ldots \label{alg:third}
    \section{Third section}
    As we showed in algorithms \ref{alg:first}, \ref{alg:second}, 
    and \ref{alg:third}, \ldots 

    enter image description here

    • Similarly to @Macro-Daniel's answer, I need numbering for the environment as a whole, not the individual items.
      – Jake
      Feb 5, 2012 at 15:37
    • @Jake: I've provided an addendum to my answer. I now interpret your question as pertaining to a custom environment that is to be numbered within sections.
      – Mico
      Feb 5, 2012 at 18:30
    • How does one make \newenvironment play well with fancyhdr? Right now it doesn't pick up the section mark at all from environments defined this way. May 1, 2020 at 15:48
    • @level1807 - I'm very sorry, but my mind-reading skills are absolutely worthless. I also have no idea how your query relates to anything in the answer above, which I wrote more than 8 years ago. May I suggest that you post a new query, in which you would lay out which issues you're encountering and what you've tried so far? Ideally, your query would be accompanied by a [Minimum (Non-)Working Example]((meta.tex.stackexchange.com/q/228/5001)). A new query has the very important benefit of being seen by far more people than a comment below an 8-year-old posting.
      – Mico
      May 1, 2020 at 15:59


    Based on the new informations of the comments I provide a new answer.

    To type an algorithm you can work the the package algorihtm. By using the command numberwithin (provided by amsmath) you can set the counter:

    \Require $x\ge5$
    \Ensure $x\le-5$
    \State $x\gets x-1$

    enter image description here

    To manipulate list environments like enumerate I really recommend the package enumitem. The package provides the key ref to manipulate the format of references.

    Here an example:

    \item \label{enum1} foo
    \item \label{enum2} bar
    \ref{enum1} and \ref{enum2}

    enter image description here

    • Please consider to add a variant using label and resume, so I can delete my answer.
      – lockstep
      Feb 5, 2012 at 15:22
    • This is close but not what I need...I edited my question to be a bit clearer
      – Jake
      Feb 5, 2012 at 15:33

    You must log in to answer this question.

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