1
$\begingroup$

I have the following Palette:

CreatePalette[Column[
   (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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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:

Cell[StyleData["DisplayFormulaCenter"],
 CellMargins->{{66, Inherited}, {Inherited, Inherited}},
 StripStyleOnPaste->True,
 DefaultFormatType->DefaultInputFormatType,
 HyphenationOptions->{"HyphenationCharacter"->"\[Continuation]"},
 LanguageCategory->"Formula",
 ScriptLevel->0,
 SingleLetterItalics->True,
 MenuSortingValue->1700,
 FontFamily->"Source Sans Pro",
 FontSize->14,
 FontColor->GrayLevel[0.2],
 TextAlignment->Center,
 UnderoverscriptBoxOptions->{LimitsPositioning->True}]

The code for DisplayFormulaNumberedCenter:

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

enter image description here

$\endgroup$
5
  • $\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.