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

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
add comment

2 Answers 2

up vote 5 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[StyleData["Section"],
  CellFrameLabels->{{
    Cell[TextData[{CounterBox["Section"], " "}],
    CellFrame -> {{0, 0}, {0, 1}}, 
    CellFrameMargins -> 4, 
    CellSize -> {30, Automatic}, 
    TextAlignment -> Right], 
   None}, {None, None}},
  CellFrameLabelMargins->0
]

Which would produce sections like this

screenshot

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

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
add comment

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.