I want to create a figure caption cell style that prefixes a centred figure caption with Figure X, where X is an incremental number

I have seen two methods for automatically numbering figures:

Method 1: Use a CellDingbat to place the label in the left margin of the notebook

   TextData[{"Figure ", 
     CounterBox["FigureCaptionNumbered"], "."}]],

Method 2: Use CellFrameLabels to place the label above, below, left or right of the cell frame. Using this method I have not been able to obtain cell frame label and the caption on the same line.

 CellMargins->{{65, 0}, {0, 0}},
 CellFrameLabels->{{None, None}, {None, 
     TextData[{"FIGURE ", 
       CounterBox["FigureCaptionNumbered"], "."}]]}},
 CellFrameLabelMargins->{{0, 0}, {0, 0}},

The image should illustrate the captions created from the described styles and my desired caption Screenshot of the two methods and my desired caption

Any ideas on how to create a style which prefixes centred text with a automatically generated number (with the number and text on the same line)?

  • $\begingroup$ If you intend to enter a new cell, separate to your graphic/plot output cell then you don't need to stick the number in a cell frame. $\endgroup$ – Mike Honeychurch Feb 18 '13 at 2:44

I have used this style:

 CellMargins->{{54, 24}, {10, -5}},
 LineSpacing->{1, 2},
 ParagraphSpacing->{0, 5},
 FontFamily->"Times New Roman",

To give me this:

enter image description here


You appear to be using a new cell for figure captions. So to get the first line underneath the plot (incidentally I made the plot align to centre) I entered a new cell and made it FigureCaption style. The typed everything bar the number, and then you just need to go to the main menu and choose Insert > Automatic Numbering ... and then choose FigureCaption as your counter. The subsequent two cells were simply cut and pastes of the initial entry. You can see that the counter automatically updates.


This code creates a button for pasting a new figure caption cell

  StyleBox[RowBox[{"Figure Caption", " ", " cell"}], 
   FontFamily -> "Helvetica", FontWeight -> "Bold"],
  Active -> True,
  ButtonFunction :> 
     Cell[TextData[{StyleBox["Fig. ", FontWeight -> "Bold"], 
        StyleBox[CounterBox["FigureCaption"], FontWeight -> "Bold"], 
        "   "}], "FigureCaption"]]],
  ButtonData :> {"\[ThinSpace]", "Text"}]]

Here is the result of repeatedly pressing the button:

enter image description here

Select the cell with the button in it and then from the menu Palettes > Generate Palette from Selection will create a palette for you and Palettes > Install Palette will make it accessible for you whenever you want it.

| improve this answer | |
  • $\begingroup$ That works, however I did want the process more automated by the style. Do you recommend an alternative method for labeling figures with the figure and the caption in the one cell? $\endgroup$ – MLD Feb 18 '13 at 3:21
  • $\begingroup$ Off the top of my head I do not know of a why to do this via stylesheets because those methods employ cell frames and you have already ruled them out. If you want it automated use a palette. See edit $\endgroup$ – Mike Honeychurch Feb 18 '13 at 5:04

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.