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

**URL:** <https://community.wolfram.com/t/can-a-style-inherit-cellmargins-depending-how-it-is-grouped/16962>\
**Category:** Questions\
**Tags:** mathematica, computational-notebooks, ui-ux-and-ide\
**Created:** [November 4, 2020, 3:48pm UTC](https://community.wolfram.com/t/can-a-style-inherit-cellmargins-depending-how-it-is-grouped/16962 "2020-11-04T15:48:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccarter](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ccarter/32/36312_2.png) [@ccarter](https://community.wolfram.com/u/ccarter)\
**Post date:** [November 4, 2020, 3:48pm UTC](https://community.wolfram.com/t/can-a-style-inherit-cellmargins-depending-how-it-is-grouped/16962/1 "2020-11-04T15:48:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ccarter](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ccarter/32/36312_2.png) [@ccarter](https://community.wolfram.com/u/ccarter)\
**Post date:** [November 6, 2020, 2:09pm UTC](https://community.wolfram.com/t/can-a-style-inherit-cellmargins-depending-how-it-is-grouped/16962/2 "2020-11-06T14:09:49Z")

</div>

I believe I found an answer here ([https://mathematica.stackexchange.com/questions/94066/how-to-inherit-indentation-in-cell-groups](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.

---

<div class="post-metadata">

**Author:** ![ccarter](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ccarter/32/36312_2.png) [@ccarter](https://community.wolfram.com/u/ccarter)\
**Post date:** [November 6, 2020, 4:47pm UTC](https://community.wolfram.com/t/can-a-style-inherit-cellmargins-depending-how-it-is-grouped/16962/3 "2020-11-06T16:47:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mikebesso](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mikebesso/32/22282_2.png) [@mikebesso](https://community.wolfram.com/u/mikebesso)\
**Post date:** [November 6, 2020, 11:46pm UTC](https://community.wolfram.com/t/can-a-style-inherit-cellmargins-depending-how-it-is-grouped/16962/4 "2020-11-06T23:46:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ccarter](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ccarter/32/36312_2.png) [@ccarter](https://community.wolfram.com/u/ccarter)\
**Post date:** [November 7, 2020, 9:00am UTC](https://community.wolfram.com/t/can-a-style-inherit-cellmargins-depending-how-it-is-grouped/16962/5 "2020-11-07T09:00:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mikebesso](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mikebesso/32/22282_2.png) [@mikebesso](https://community.wolfram.com/u/mikebesso)\
**Post date:** [November 7, 2020, 2:53pm UTC](https://community.wolfram.com/t/can-a-style-inherit-cellmargins-depending-how-it-is-grouped/16962/6 "2020-11-07T14:53:53Z")

</div>

Thanks.

---

<div class="post-metadata">

**Author:** ![ccarter](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ccarter/32/36312_2.png) [@ccarter](https://community.wolfram.com/u/ccarter)\
**Post date:** [November 15, 2020, 9:04pm UTC](https://community.wolfram.com/t/can-a-style-inherit-cellmargins-depending-how-it-is-grouped/16962/7 "2020-11-15T21:04:44Z")

</div>

This has been answered in [StackExchange](https://mathematica.stackexchange.com/questions/234486/can-a-style-inherit-cellmargins-depending-how-it-is-grouped)  
There are several solutions, but [@Carl Woll](https://community.wolfram.com/web/carlw) 's is the easiest to implement:

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

```

[@Carl Woll](https://community.wolfram.com/web/carlw)  
[1]: [https://mathematica.stackexchange.com/questions/234486/can-a-style-inherit-cellmargins-depending-how-it-is-grouped](https://mathematica.stackexchange.com/questions/234486/can-a-style-inherit-cellmargins-depending-how-it-is-grouped)
