Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create a LaTex-style document with Section numbers of the form 1.0 and then subsection numbers 1.1, 2.1, etc. I need the numbering to be automatic such that if I insert a new subsection, the numbering of subsequent subsections will automatically adjust. Is there an easy way to do this (presumably by editing the stylesheet??). I've looked at a bunch of options but can't seem to find the appropriate one.

share|improve this question
up vote 8 down vote accepted

This question might help.

In short, to get an automatically numbered section or subsection you could edit the CellFrameLabels or the CellDingbat option of the relevant style definitions.

  • Open a new notebook, add a section cell, and select Edit Stylesheet... in the Format menu
  • Choose Section from the drop down menu in the stylesheet editor and select the newly created cell
  • Check Show Expression in the Cell menu which
  • Add either the option CellFrameLabels-> {{spec, None}, {None, None}} or CellDingbat -> spec somewhere after the first argument where spec is the specifications for the section number.
  • Uncheck Show Expression. Sections in the should then be numbered automatically
  • You can install the updated stylesheet by pressing the Install Stylesheet... button in the stylesheet editor

In its simplest form the number specification would be something like

 Cell[TextData[{ CounterBox["Section"]}]]

for a section or

Cell[TextData[{ CounterBox["Section"], ".", CounterBox["Subsection"]}]]

for a subsection, but you can add your own styling to the numbering. For example for a notebook using the default stylesheet you could set the style definition of Section to something like

    Cell[TextData[{CounterBox["Section"], " "}],
    CellFrame -> {{0, 0}, {0, 1}}, 
    CellFrameMargins -> 4, 
    CellSize -> {30, Automatic}, 
    TextAlignment -> Right], 
   None}, {None, None}},

Which would produce sections like this


share|improve this answer
Ah, very nice. Your example worked very well. Many thanks. – Eric Jan 30 '12 at 16:55

You can add automatic numbering using Insert | Automatic numbering.... The menu is pretty self-explanatory; to have a numbering that resets with every new "Alt+4" headline, select Section as counter. To have something like Section.Subsection, you'll have to use that menu twice, and then put the dot between the numbers manually.

I do not know how to automatically do this via the stylesheet, so unfortunately I'm limited to doing this every time I create a new headline. You can however copy+paste the automatic numbering, replace the actual caption in the new place, and you'll have just what you want.

share|improve this answer

Your Answer


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.