Search code examples
wolfram-mathematicamathematica-frontend

CellDingbat is below the first line of the Cell


According to the Documentation, "Dingbats are placed to the left of the main contents of a cell, aligned with the first line of the contents." But when I evaluate

CellPrint@Cell[BoxData["Text"], CellDingbat -> "CellDingbat"]

in a Notebook with the "Default" stylesheet I get

screenshot

One can see that the CellDingbat is placed lower than the first line of the Cell. Why this happens? Is there a way to align CellDingbat with the first line of the Cell?


Solution

  • Provided you don't want the CellDingbat on a standard "Input" or "Code" cell style, then as pointed out by Sjoerd, the cell's contents and dingbat automatically align. It's only when you wrap the cell contents in BoxData that they become misaligned.

    If the cell you want is a "Text" or "Section" (etc) cell, then you can still have formatted text provided the cell contents are contained in TextData[...]. For example

    dingBaT

    Note that I've started the text and ended the dingbat with a capital T so that the alignment is clear.

    If you hand make your "Input" cells to have their contents wrapped in TextData (which does not happen by default) then the code will run, but the styling is not quite right. The spacing is wrong and syntax highlighting not active. Compare the following

    input

    The first printed cell has syntax highlighting but the cell dingbat is misaligned, while the second printed cell has no syntax highlighting and poor spacing, but the dingbat is perfectly aligned!


    Finally, I should have realised that a solution like this would work, because I've been using cell dingbats for automatic section numbering for ages and have never had alignment problems. E.g., here's the outline of a notebook I was working on last week that contains supporting code for a chapter in my thesis:
    WZ
    The section and subsection cells are given dingbats in the stylesheet, e.g.,
    CellDingbat->TextData[{CounterBox["Section"], ". "}].