Re: Automatic numbered captions for figures (plots)
- To: mathgroup at smc.vnet.net
- Subject: [mg18191] Re: Automatic numbered captions for figures (plots)
- From: paulh at wolfram.com (P.J. Hinton)
- Date: Mon, 21 Jun 1999 22:50:33 -0400
- Organization: Wolfram Research, Inc.
- References: <7kholg$qpq@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <7kholg$qpq at smc.vnet.net>, "William F. Campbell" <valentin at wam.umd.edu> writes: > I'd like to be able to do generate a graphic, then automatically generate a cell > in myFigureStyle that has automatic numbering. I have figured out part of the > process. Inside whatever graphics command I use, I use > Epilog->{CellPrint[Cell["I enter the figure description here",myFigureStyle]]}. > But I haven't figured out (no pun intended) how to get the cell to start with > Figure 1., so that it actually looks like > > Figure 1. I enter the figure description here > > and the next time I use it, > > Figure 2. Here's the caption for my next figure. > > In other words, I don't know how to define myFigureStyle. You need to add the style to the style sheet in use by your notebook. Actually, I think the following approach may be a bit cleaner: 1) Define a function that will serve as an alternative to the standard $DisplayFunction used when you show graphics. This function will take the graphics object as its argument and will call CellPrint[] twice. The first call generates the PostScript version of the graphic, and the second places the caption cell. captionedGraphic[ gr : (_Graphics | _Graphics3D | _SurfaceGraphics | _ContourGraphics | _DensityGraphics)] := (CellPrint[ Cell[GraphicsData["PostScript", DisplayString[gr]], "Graphics"] ]; CellPrint[ Cell[TextData["I enter the figure description here"], "NumberedCaption"] ] ) You then use this function like so: Plot[Sin[x], {x, 0, 2Pi}, DisplayFunction -> captionedGraphic] 2) Now we need a definition for the NumberedCaption style. Here is one based on the Caption style found in the Textbook style sheet: Cell[StyleData["NumberedCaption"], CellMargins->{{10, 50}, {0, 3}}, PageBreakAbove->False, CellFrameLabels->{ {Cell[TextData[ {"Figure ", CounterBox[ "NumberedCaption"]}]], None}, {None, None} }, CounterIncrements -> {"NumberedCaption"}, Hyphenation->True, FontFamily->"Helvetica", FontSize->9], Cell[StyleData["NumberedCaption", "Printout"], CellMargins->{{2, 50}, {2, 4}}, FontSize->7] The options you need to note here are CellFrameLabels and CounterIncrements. CellFrameLabels is how you can embed a counter in a region that is not part of the textual body of the cell. It takes a list of strings or Cell[] expressions which represent left, right, bottom, and top labels. 3) The CounterIncrements tells the front end that the presence of this cell should bump the "NumberedCaption" counter by one unit. Now we need to tell the front end where to start counting. The CounterAssignments option is used to fix the counter at a starting value. You can zero out the counter by adding a setting in a heading cell. For example the Section style's prototype has this option: CounterAssignments->{{"Subsection", 0}, {"Subsubsection", 0}} We could add the "NumberedCaption" counter to this list: CounterAssignments->{{"Subsection", 0}, {"Subsubsection", 0}, {"NumberedCaption", 0}} For further reading, see my tutorial on CounterBox objects here: http://www.mathsource.com/Content/General/Tutorials/Programming/0209-821 > On a related note, I couldn't find out what all the available predefined styles > are (for cells). I read somewhere that not all the styles are in the > Format|Styles menu. In the appropriate section of the Mathematica book, a style called > NumberedEquation is mentioned, but I couldn't find it anywhere (thus I cannot > use it). I have a list of such style sheets in the tutorial notebook. -- P.J. Hinton Mathematica Programming Group paulh at wolfram.com Wolfram Research, Inc. Disclaimer: Opinions expressed herein are those of the author alone.