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

Cell[StyleData["FigureCaptionLeft"],
 CellDingbat->Cell[
   TextData[{"Figure ", 
     CounterBox["FigureCaptionNumbered"], "."}]],
 TextAlignment->Left,
 CounterIncrements->"FigureCaptionNumbered",
 CellMargins->{{115,0},{0,0}},
 MenuSortingValue->10000]

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.

Cell[StyleData["FigureCaptionCentred"],
 CellMargins->{{65, 0}, {0, 0}},
 CellHorizontalScrolling->True,
 CellFrameLabels->{{None, None}, {None, 
    Cell[
     TextData[{"FIGURE ", 
       CounterBox["FigureCaptionNumbered"], "."}]]}},
 CellFrameLabelMargins->{{0, 0}, {0, 0}},
 TextAlignment->Center,
 CounterIncrements->"FigureCaptionNumbered"]

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)?

share|improve this question
    
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. –  Mike Honeychurch Feb 18 '13 at 2:44

1 Answer 1

I have used this style:

Cell[StyleData["FigureCaption"],
 CellMargins->{{54, 24}, {10, -5}},
 TextAlignment->Center,
 LineSpacing->{1, 2},
 ParagraphSpacing->{0, 5},
 LanguageCategory->"NaturalLanguage",
 ScriptLevel->1,
 CounterIncrements->"FigureCaption",
 FontFamily->"Times New Roman",
 FontSize->12]

To give me this:

enter image description here

Explanation:

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.

Edit

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

DisplayForm[
 ButtonBox[
  StyleBox[RowBox[{"Figure Caption", " ", " cell"}], 
   FontFamily -> "Helvetica", FontWeight -> "Bold"],
  Active -> True,
  ButtonFunction :> 
   CompoundExpression[
    NotebookWrite[InputNotebook[], 
     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.

share|improve this answer
    
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? –  MLD Feb 18 '13 at 3:21
    
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 –  Mike Honeychurch Feb 18 '13 at 5:04

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.