The purpose can be achieved with CellFrameLabels
. Cell-expressions and Boxes can be used directly here, so styling can be done with StyleBox
, alignment can be done with PanelBox
etc. The counter mechanics is exact as Simon demonstrated in the linked Q/A in OP.
Here is an example:
cellFrameLabelFunc
uses PanelBox
with Alignment
to align label lbl
from left (-1
) to right (1
):
Clear[cellFrameLabelFunc]
cellFrameLabelFunc[lbl_, align_: 0, color_: White] :=
PanelBox[lbl,
ImageSize -> {Scaled[1], Automatic},
Alignment -> {align, Center},
Appearance -> "Frameless", Background -> color
]
We pre-assign the align_
then construct the label as following:
alignFraction = 0.3;
With[{
counterSet =
ToString[Hue[#, .4, .95], StandardForm] & /@ Range[0, 1, .2]
},
testlbl =
Style["my cell frame label", 13, Red, Italic,
FontFamily -> "Constantia"] //
ToBoxes //
RowBox[{#, " & my counter : ",
CounterBox["myCounter",
CounterFunction :> (Part[counterSet, #] &)] //
StyleBox[#,
FontFamily -> "Constantia", FontSize -> 30,
FontWeight -> Bold,
FontColor -> Hue[0.75, 0.38, 0.78]] &
}] & //
cellFrameLabelFunc[#, alignFraction] &
];
And generate the cells:
Cell["", CounterAssignments -> {{"myCounter", 0}}] // CellPrint
Cell[
ConstantArray["this is the main body ", 6] // StringJoin,
"myStyle",
CellFrameLabels -> {{None, None}, {testlbl, None}},
CounterIncrements -> "myCounter"
] // Do[CellPrint@#, {5}] &
CellFrameLabels
. $\endgroup$