Extending cell definition to CellFrameLabels definition

爱⌒轻易说出口 提交于 2019-11-29 04:40:38
Simon

I don't think that it's possible to do in the way you want. CellLabels can only be text, while both CellDingbat and CellFrameLabels can be arbitrary cell expressions.

Both CellDingbat -> ... and CellFrameLabels -> {{...,None},{None,None}} work if the cell is only a single line long. But do not automatically resize for multiple line cells (at least as far as I could tell). For example:

Cell["Abcdefg", "Text",
 CellFrame->{{0, 1}, {0, 2}},
 CellMargins->{{30, 24}, {6, 6}},
 CellFrameMargins->0,
 CellFrameColor->RGBColor[0, 0, 1],
 CellFrameLabels->{{Cell[" Definition 1.1  ", "Text", 
   CellFrame -> {{2, 0}, {0, 2}}, CellFrameMargins -> 0], None}, {None, None}},
 CellFrameLabelMargins->0,
 Background->RGBColor[0, 1, 1]]

Putting a CellFrameLabel on the top does not have this problem, but I don't know how to align it to the left...

Cell["Abcde", "Text",
 CellFrame->{{1, 1}, {0, 2}},
 CellMargins->{{30, 24}, {6, 6}},
 CellFrameMargins->0,
 CellFrameColor->RGBColor[0, 0, 1],
 CellFrameLabels->{{None, None}, {None, 
    Cell[" Definition 1.1 ", "Text", 
     CellFrame -> {{2, 2}, {0, 2}}, CellFrameMargins -> 0]}},
 CellFrameLabelMargins->0,
 Background->RGBColor[0, 1, 1]]

I think that maybe the best looking solution would be to include the "Definition ch.def:" in the cell contents.

Cell[TextData[{
 Cell["Definition 1.1:   ", Editable->False, Selectable->False, Deletable->False],
 "Abcdefg"}], "Text",
 CellFrame->{{1, 1}, {0, 2}},
 CellMargins->{{30, 24}, {6, 6}},
 CellFrameColor->RGBColor[0, 0, 1],
 Background->RGBColor[0, 1, 1]]

Make it so that it's not deletable by the average user and it is probably almost as good as a cell(frame)label. It can include counters so that it automatically shows the correct numbering. The only problem is that it does not appear automatically, but if you just copy a pre-existing cell, then that's not too much of a problem.


Edit: Adding an input alias that creates the non-deletable counter

First we get the current input aliases,

oldAliases = InputAliases /. Options[EvaluationNotebook[], InputAliases];

then replace any existing alias EscdefEsc with our new one:

newAliases = 
  Append[DeleteCases[oldAliases, "def" -> _], 
   "def" -> Cell[TextData[
     RowBox[StyleBox[#, FontWeight->"Bold", FontColor->Blue]&/@{"Definition ", 
      CounterBox["Chapter"], ".", CounterBox["Definition"], ":   "}]],(*"Text",*)
     Editable -> False, Selectable -> False, Deletable -> False]];  
SetOptions[EvaluationNotebook[], InputAliases -> newAliases]

Since I don't have your style sheet, I need to set a couple of counters:

CellPrint[Cell["Setting the counters", "Text", 
  CounterAssignments -> {{"Chapter", 2}, {"Definition", 3}}]]

Now I can use the alias in an existing cell - it inherits the styling of the parent cell (unless otherwise specified):


Another option is to make a palette to go with your stylesheet. This would be useful since there's only a limited number of MenuCommandKey values that you can use for your new styles (n.b. overwriting the default ones will just confuse people). See this answer for an example of such a palette.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!