10
$\begingroup$

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.

$\endgroup$
12
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Ah, very nice. Your example worked very well. Many thanks. $\endgroup$ – Eric Jan 30 '12 at 16:55
3
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ (+1) this is a way that a lazy guy like me do! :D $\endgroup$ – H. R. Apr 22 '17 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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