Message Boards Message Boards

0
|
5181 Views
|
10 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Change the vertical alignment of text in a cell dingbat?

Posted 8 years ago

From the Wolfram documentation, I understand that a cell dingbat (circle, square, ...) is aligned with the first line in the cell (which makes sense for creating bullet points, for example).

I want to create a cell dingbat that contains text and I want to control the vertical alignment of the text in that cell. Here is the code I have so far:

CellPrint[
 TextCell["Some text for my cell",
       CellDingbat -> Cell[
          TextData["Ex. 1"],
          CellSize -> {48, 24}, CellFrame -> True,
            CellMargins -> {{0, 0}, {0, 10}},
          CellFrameMargins -> {{10, 0}, {0, 0}},
          TextAlignment -> Left,
          FontSlant -> Italic, FontWeight -> Bold,
          Background -> GrayLevel[.9]]
  ]]

This produces the dingbat with text still aligned with the first line in the cell:

Bad Dingbat

I have tried numerous things, including setting the CellBaseline and adjusting the CellFrameMargins, but I can't get the "Ex. 1" text to have more space between it and the top of the CellFrame. Note: I want to keep the current frame for the dingbat cell exactly as is (I want it aligned with the top of the main text in the cell), so increasing the CellFrameMargin for the TextCell is not a desired workaround.

Can someone explain how to achieve this spacing? Thanks.

POSTED BY: Andrew
10 Replies
Posted 8 years ago

Here is the solution:

CellPrint[
 TextCell["Some text for my cell",
       CellDingbat ->
           Cell[
           RowBox[AdjustmentBox["Ex. 1", BoxBaselineShift -> .8]],
           CellSize -> {48, 36},
           TextAlignment -> Left,
           FontSlant -> Italic, FontWeight -> Bold,
           CellFrame -> True,
           CellFrameMargins -> {{5, 0}, {0, 0}},
           Background -> GrayLevel[.8]
        ]
  ]
 ]

Not sure why CellFrameMargins don't do the trick (it works for the left margin but not the top margin)—I guess it has something to do with the way Mathematica has implemented the CellDingBat.

POSTED BY: Updating Name

It's not exactly Andrew wants, because "Out[...]=" misses in the output. Nevertheless, it's very appropriate.

Posted 8 years ago

I have not yet found a solution, but here is a graphic that illustrates what I'm trying to achieve: goal

The best workaround I've managed is to adapt Valeriu's code as shown below. It's not a complete solution because there is no control over the vertical spacing (it's fixed because it's a blank line):

CellPrint[
 TextCell["Some text for my cell", 
  CellDingbat -> 
   Cell[Column[{"   ", "Ex. 1"}], CellSize -> {72, 48}, 
    CellFrame -> True, CellMargins -> {{0, 0}, {0, 10}}, 
    CellFrameMargins -> {{10, 0}, {0, 0}}, TextAlignment -> Left, 
    FontSlant -> Italic, FontWeight -> Bold, 
    Background -> GrayLevel[.9]]]]

This code results in the following:

enter image description here

POSTED BY: Andrew

There is a good function for these types of problems Spacer[], but it unfortunately doesn't work in this case...

Posted 8 years ago

This doesn't have the top of the CellDingbat Cell aligned with the first line of text, so it doesn't quite achieve what I'm looking for. I think the solution, which I will attempt later, is to nest a second cell (that contains the "Example" text) inside the main CellDingbat cell that has the frame and the gray background. The cell margins of that inner cell can be then used to position the text.

Thanks again.

POSTED BY: Andrew

My pleasure!

Dear Andrew,

If you solved the problem, please post the solution and the result. It's interesting to know what was your goal and how to overcome the difficulty!

Thanks.

CellPrint[
 TextCell["Some text for my cell Some text for my cell Some text for \
my cell Some text for my cell Some text for my cell Some text for my \
cell Some text for my cell Some text for my cell Some text for my \
cell Some text for my cell Some text for my cell Some text for my \
cell Some text for my cell Some text for my cell Some text for my \
cell Some text for my cell Some text for my cell Some text for my \
cell Some text for my cell Some text for my cell Some text for my \
cell ", CellDingbat -> 
   Cell[Column[{"", "Example 1.", "Vertical", "Alignment"}], 
    CellSize -> {80, 60}, CellFrame -> True, 
    CellMargins -> {{0, 0}, {0, 10}}, 
    CellFrameMargins -> {{10, 0}, {0, -20}}, TextAlignment -> Left, 
    FontSlant -> Italic, FontWeight -> Bold, 
    Background -> GrayLevel[.9]], CellMargins -> {{400, 600}, {4, 4}},
   CellChangeTimes -> {{3, 3}}]]

enter image description here

Posted 8 years ago

It's close to a solution because it does put space between "Example 1." and the top frame of the CellDingbat. However to achieve that, it seems you used:

CellMargins -> {{400, 600}, {4, 4}}

for the main cell that contains the CellDingBat cell. As you can see in your image, this causes the "Some text for..." to no longer to be aligned with the CellDingbat frame, which is reall what I want to achieve.

Another way of stating what I'm trying to do is no longer force "Example 1." to be aligned with the first line of "Some text for my..."; that is, I want "Example 1." to be lower than the first line of "Some text for my...".

Thanks for you help!

POSTED BY: Andrew

I am not sure this code satisfies your desires that are somewhat unclear, but may be it will serve as a starting point to overcome the difficulty...

CellPrint[
 TextCell["Some text for my cell Some text for my cell Some text for \
my cell Some text for my cell Some text for my cell Some text for my \
cell Some text for my cell Some text for my cell Some text for my \
cell Some text for my cell Some text for my cell Some text for my \
cell Some text for my cell Some text for my cell Some text for my \
cell Some text for my cell Some text for my cell Some text for my \
cell Some text for my cell Some text for my cell Some text for my \
cell ", CellDingbat -> 
   Cell[Column[{"Example 1.", "Vertical", "Alignment"}], 
    CellSize -> {80, 60}, CellFrame -> True, 
    CellMargins -> {{0, 0}, {0, 10}}, 
    CellFrameMargins -> {{10, 0}, {0, 0}}, TextAlignment -> Left, 
    FontSlant -> Italic, FontWeight -> Bold, 
    Background -> GrayLevel[.9]], CellMargins -> {{400, 600}, {4, 4}},
   CellChangeTimes -> {{3, 3}}]]

enter image description here

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract