Specify position of button

This might go against the spirit of Mathematica, but I would like to create the button, but I do not want that button to be grouped with the code that generated it. In fact, the code that generates it is inside a Style environment (Section) and I would like that the button shows up right "outside" all the style environment. As a screenshot, it would look like this: is that sort of thing possible?

You can modify the CellGroupingRules of the cell created by the button. You will also need to modify the "EvaluationUnmatchedStyle" setting of the printed cell, otherwise it is faded when printed. In both cases, you can do this using CellPrint:

CellPrint @ ExpressionCell[
Button[
"Print",
CellPrint @ ExpressionCell[
"Hello world!",
"Print",
PrivateCellOptions->{"EvaluationUnmatchedStyle"->{}}
]
],
"Output",
CellGroupingRules->"SectionGrouping"
]


Here's a screenshot:

If you have manual grouping turned on, then you will need to make use of SelectionMove and NotebookWrite instead:

With[{sec=PreviousCell[CellStyle -> "Section"]},
SelectionMove[sec, All, CellGroup];
SelectionMove[EvaluationNotebook[], After, Cell];
NotebookWrite[
EvaluationNotebook[],
ToBoxes@Button[
"Print",
Print["Hello world!"]
]
]
]


Screenshot:

• This works, but only if I set the automatic cell grouping back to on. I prefer to set it to manual, in which case the above does not work. Is there a way to make it work for manual cell groupings? – Patrick.B Jun 20 '19 at 20:52