You can achieve this by grouping cells manually instead of relying on the automatic grouping mechanism. In the notebook in question, use the "Cell / Grouping / Manual Grouping" element to enable manual grouping. Now, when you enter sections, subsections, etc., they will not be grouped automatically. Select the cells that should be in the same group and use the menu item Cell / Group / Group cells / Group together. Now that they are grouped, you can set CellContext as a CellGroup, and they will all fit together well.
source share