3
$\begingroup$

I have defined the following Input/Output styles in my stylesheet:

Cell[StyleData["Input"],
 CellMargins->{{65, 0}, {0, 5}},
 CellGroupingRules->{"GroupTogetherGrouping", 10000.},
 CellChangeTimes->{3.850893359505125*^9, 3.8508938629674664`*^9},
 FontFamily->"IBM Plex Mono",
 FontWeight->"Medium",
 Background->RGBColor[0.8980392156862745, 0.9647058823529412, 1., 0.6]]

and

Cell[StyleData["Output"],
 CellMargins->{{65, 0}, {5, -1}},
 CellGroupingRules->{"GroupTogetherGrouping", 10000.},
 CellChangeTimes->{3.8508933595049973`*^9, 3.85089386296737*^9},
 FontFamily->"IBM Plex Mono",
 FontWeight->"Regular",
 Background->RGBColor[0.933333, 0.388235, 0.388235, 0.1]]

This is what they look like:

style pic

In the stylesheet notebook, the blue and red boxes are overlapping each other just a wee bit and there are no gaps no matter the magnification.

This breaks in a separate notebook where I apply the stylesheet. After some minimum magnification, the blue and red boxes separate.

Good behavior @ low magnification

enter image description here

Bad behavior @ high magnification

enter image description here

Is there a way to fix this behavior?

$\endgroup$

1 Answer 1

3
$\begingroup$

After some digging into the options of Cell, I realized what the culprit was. Turns out, my stylesheet was inheriting the option CellLabelPositioning->Automatic from the Default.nb stylesheet.

The documentation page of CellLabelPositioning says that the Automatic option will place cell labels like In[lineno]:= or Out[lineno]:= in new cells (which of course don't have the custom background color) above the input/output cell if it thinks it is too big to fit in the left margin. Of course zooming scales everything and so it should still fit if it originally did. But the Automatic option somehow misses that and puts them above in a new cell anyways.

The fix is then to manually add the option CellLabelPositioning->Left to the Input/Output cell styles in my stylesheet which overrides the default setting. With this option, the cell labels are always on the left margin no matter the magnification and do not interfere with my desired formatting.

Corrected definitions of Input/Output cell styles

Input Cell Style

Cell[StyleData["Input"],
 CellMargins->{{65, 0}, {0, 5}},
 CellChangeTimes->{3.850893359505125*^9, 3.8508938629674664`*^9},
 FontFamily->"IBM Plex Mono",
 FontWeight->"Medium",
 Background->RGBColor[0.8980392156862745, 0.9647058823529412, 1., 0.6],CellLabelPositioning->Left]

Output Cell Style

Cell[StyleData["Output"],
 CellMargins->{{65, 0}, {5, 0}},
 CellChangeTimes->{3.8508933595049973`*^9, 3.85089386296737*^9},
 FontFamily->"IBM Plex Mono",
 FontWeight->"Regular",
 Background->RGBColor[0.933333, 0.388235, 0.388235, 0.1],CellLabelPositioning->Left]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.