Message Boards Message Boards

Can a Style inherit CellMargins depending how it is grouped?

Posted 4 years ago

I'd like to have the Styles Item, Subitem, and Subsubitem indent relative to which group they are located. Here is a concrete example to explain what I mean:

CreateDocument[
 {
  Cell["This is a section", "Section"],
  Cell["This is an item in a section", "Item"],
  Cell["This is a Subitem in a section", "Subitem"],
  Cell["This is a Subsubitem in a section", "Subsubitem"],
  Cell["This is a Subsection", "Subsection"],
  Cell["This is an item in a section", "Item"],
  Cell["This is a Subitem in a Subsection", "Subitem"],
  Cell["This is a Subsubitem in a Subsection", "Subsubitem"],
  Cell["This is a Subsubsection", "Subsubsection"],
  Cell["This is an item in a Subsubsection", "Item"],
  Cell["This is a Subitem in a Subsubsection", "Subitem"],
  Cell["This is a Subsubitem in a Subsubsection", "Subsubitem"]}
 ]

Notice that the item-like styles all have the same indentation--the indentation doesn't depend on the indentation of Section, Subsection, Subsubsection...

If I edit the Stylesheet for that document and use:

Cell[StyleData["Item"],
 CellMargins->{{Inherited + 20, Inherited}, {Inherited, Inherited}}]

Cell[StyleData["Subitem"],
{{Inherited  + 40, Inherited}, {Inherited, Inherited}}]

Cell[StyleData["Subsubitem"],
CellLabelMargins->{{Inherited  + 60, Inherited}, {Inherited, Inherited}}
]

They are inheriting the left-hand cell margin, but where are they inheriting from?

More to the point, can I make a stylesheet where item-like indentation is relative to the group where the item lives. For example, an Item in a Subsection inherits the margins of the Subsection, an Item in a Subsubsection inherits from Subsubsection.

POSTED BY: W. Craig Carter
6 Replies

I believe I found an answer here (https://mathematica.stackexchange.com/questions/94066/how-to-inherit-indentation-in-cell-groups)

In the Stylesheeet:

Cell[StyleData["Item"],
CellMargins -> AbsoluteCurrentValue[PreviousCell[], CellMargins]+{{24,0},{0,0}}

does what I was looking for.

POSTED BY: W. Craig Carter

Nope. Upon further testing, it doesn't work.

POSTED BY: W. Craig Carter
Posted 4 years ago

I have also been wondering how to do this as well.

POSTED BY: Mike Besso

Hi Mike, I'm going to try a few other approaches, but it may be a while before I get back to it.

POSTED BY: W. Craig Carter
Posted 4 years ago

Thanks.

POSTED BY: Mike Besso

This has been answered in StackExchange There are several solutions, but @Carl Woll 's is the easiest to implement:

CellMargins->AbsoluteCurrentValue[
PreviousCell[CellStyle->Alternatives["Text","Section"]],CellMargins]+{{24,0},{0,0}}

@Carl Woll

POSTED BY: W. Craig Carter
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