Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill in CellFrameLabels in Mathematica Notebook Styles?

I have been working on getting numbered cell-frame labels following the great advice in these other answers

Extending cell definition to CellFrameLabels definition

How to Autonumber Cell Tags in Mathematica Notebooks?

and I'm almost there. I wanted to add section numbers to section styles in the Creative / Pastel colors stylesheet. I created a new notebook (here's a copy on my public dropbox)

http://dl.dropbox.com/u/1997638/CellFrameMargins.nb

went to "Format" menu, chose "Stylesheet \ Creative \ PastelColor," then "Format" "Edit Stylesheet", "Choose a style: Section", then click on Creative\Pastelcolor.nb at the top of the stylesheet-editing dialog.

That opens another stylesheet editor, and I go to the fourth item down "Styles for Title and Section Cells," then the second item in there "Section." Put mouse crosshairs in there and click, then choose "Cell" menu, "Show Expression" item, which reveals the following expression:

Cell[StyleData["Section"],
 CellFrame->{{0, 0}, {1, 3}},
 CellFrameColor->RGBColor[1., 0.819608, 0.658824],
 FontFamily->"Helvetica",
 FontSize->18,
 FontWeight->"Bold",
 FontColor->RGBColor[0.882353, 0.419608, 0.0784314],
 Background->RGBColor[1., 0.886275, 0.741176]]

GREAT! Reveals all the details, or so I thought. In particular, the CellFrame item gives me the {{0, 0}, {1, 3}} info I need to line up my cell frame labels with the Section style. Ok, so back to the steylsheet editor dialog for my notebook, and following the aforementioned answers, I type

Cell[
 StyleData["Section"],
 CellFrameLabelMargins -> 0,
  CellFrameLabels-> { {
   Cell[
    TextData[{ "§", CounterBox["Section"], ": " }], 
    "SectionLabel",
    CellFrame -> {{0, 0}, {1, 3}},
    CellFrameMargins -> 4
   ] (* left label *),
   Inherited (* right label *) }, 
  {Inherited (* bottom label *), 
   Inherited (* top label *) } } ]

The CellFrameMargins -> 4 rule I found by trial-and-error is needed to line up the top and bottom of the cell frame with the rest of the Section style to the right. I'm sad to report that it only almost works. There are gaps between the text of the CellFrameLabels and the frames, and I want to fill in those gaps. It's as though the fonts in the CellFrameLabels don't stretch up and down far enough, even though they're exactly the same as the fonts in the Section cells. I can't find a way to fill in the background behind the labels. I tried Background -> RGBColor[...], I tried putting in explict fonts, I tried setting the CellFrameMargins, and the CellFrameLabelMargins, in many many combinations, but to no avail.

I'm stumped and would appreciate any advice.

Screenshot

like image 977
Reb.Cabin Avatar asked Oct 08 '22 22:10

Reb.Cabin


1 Answers

This seems to work for the pastel style. What this does is putting the label inside a frame. I had to fiddle a bit with the ImageMargins and FrameMargins of the FrameBox to make everything align.

Cell[StyleData["Section"],
 CellFrameLabels->{{
  Cell[
   BoxData[
    FrameBox[
     TemplateBox[{"§", CounterBox["Section"], ": "},
      "Row",
       DisplayFunction->(RowBox[{#, " ", #2}]& )
     ],
     ImageMargins->-1,
     Background->RGBColor[1., 0.886275, 0.741176],
     FrameStyle->RGBColor[1., 0.886275, 0.741176],
     FrameMargins->2
    ]
   ], 
   "SectionLabel", CellFrame -> {{0, 0}, {1, 3}}, 
   CellFrameMargins->0
  ], Inherited}, 
  {Inherited, Inherited}},
 CellFrameLabelMargins->0
]

Screenshot: screen shot

like image 171
Heike Avatar answered Oct 13 '22 10:10

Heike