I have the following Palette:

   (Button[Style[#1, 20, FontFamily -> "Calibri"], 
          FrontEndTokenExecute[InputNotebook[], "Style", #1], 
          Appearance -> "Palette", ImageSize -> 250] & ) /@ 
     {"Title", "Subtitle", "Subsubtitle", "Section", 
       "Subsection", "Subsubsection", "Text", 
       "DisplayFormula", "DisplayFormulaNumbered"}, 
   Spacings -> 0]];

I want to add two buttons, after "DisplayFormula" and "DisplayFormulaNumbered", that display the test (centred) and which format the cells as Format->DisplayFormula + Format->Text Alignment->Align Center and Format->DisplayFormulaNumbered + Format->Text Alignment->Align Center respectively.

How do I do this?

If it's not possible to create one button for two formatting instructions, then how do I add a button that performs Format->Text Alignment->Align Center?


1 Answer 1


One way is to edit the stylesheet for your notebook to add two new styles:DisplayFormulaNumberedCenter and DisplayFormulaCenter. Then you can use the same code by adding these two items to your list.

  1. Select your notebook
  2. Go to Format>Edit Stylesheet
  3. Enter a style name (one of the two above) + ENTER
  4. Select the cell where it appears and select Cell>Show Expression
  5. Replace the full expression by the one below corresponding to your style. These are copies of the definitions in the default notebook for their uncentered counterparts, modified with the name of the new style and the center alignment.
  6. Cell>Show Expression to go back to normal display
  7. Repeat for the other style
  8. Close (or intstall) the style sheet
  9. The notebook now recognizes the new styles

The code for DisplayFormulaCenter:

 CellMargins->{{66, Inherited}, {Inherited, Inherited}},
 FontFamily->"Source Sans Pro",

The code for DisplayFormulaNumberedCenter:

Cell[StyleData["DisplayFormulaNumberedCenter", StyleDefinitions -> StyleData["DisplayFormula"]],
       CounterBox["DisplayFormulaNumberedCenter"], ")"}], "DisplayFormulaEquationNumber"]}, {None, None}},
 CounterIncrements->"DisplayFormulaNumberedCenter", TextAlignment->Center,

enter image description here

  • $\begingroup$ Many thanks @Jean-Pierre. Can I ask a follow-up before marking this as answered? Is there a way to do this globally, or are stylesheets by definition notebook-specific? $\endgroup$ Jan 21, 2021 at 9:51
  • $\begingroup$ With the stylesheet open in Edit Stylesheet, click Install Stylesheet and save it under a name of your choice, such as CenteredFormula. Now the style sheet is listed in the munu under Format>Stylesheet and can be selected for any notebook that is using the Default stylesheet (assuming the new stylesheet was created from the Default stylesheet, but it could be created from other stylesheets). $\endgroup$ Jan 21, 2021 at 12:06
  • $\begingroup$ Fantastic. Many thanks. $\endgroup$ Jan 21, 2021 at 12:21
  • $\begingroup$ Note that for the numbered version, you may wish to use the same counter for the center and left alignment. This requires modifying the code to: CounterBox["DisplayFormulaNumbered"] and CounterIncrements->"DisplayFormulaNumbered" $\endgroup$ Jan 21, 2021 at 12:47
  • $\begingroup$ Thanks so much @Jean-Pierre. I just added an uptick to your answer. I really appreciate the extra info. $\endgroup$ Jan 21, 2021 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.