# Can a Style inherit CellMargins depending how it is grouped?

Posted 1 year ago
2261 Views
|
6 Replies
|
2 Total Likes
|
 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.
6 Replies
Sort By:
Posted 1 year ago
 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 1 year ago
 Nope. Upon further testing, it doesn't work.
Posted 1 year ago
 I have also been wondering how to do this as well.
Posted 1 year ago
 Hi Mike, I'm going to try a few other approaches, but it may be a while before I get back to it.
Posted 1 year ago
 Thanks.
Posted 1 year ago
 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}} 
Community posts can be styled and formatted using the Markdown syntax.