I am well aware of how to manually center the contents of an output cell (Format>TextAlignment>AlignCenter), and how to force all output cells to be aligned in the center (as shown here). I also know how to use CellPrint and related functions to force an output cell to be centered (as shown here). But I don't want to type such a wrapper every time I want to simply Plot.

I need something just a bit different: I'd like the output of every plot (Plot, Plot3D, DiscretePlot, ...) to be centered in the output cell, but not center the output of other functions, for instance from calculations. (All this is for presentation slides, where centered figures look best.)

I thought the right approach would be to set an Option -> (TextAlignment ->Center) for Plots in an initialization cell, but TextAlignment is not an option proper for plots.

How do I set some option to center all plot outputs, but not the outputs of other functions?

  • 1
    $\begingroup$ Maybe $Post = Replace[#, g : _Graphics | _Graphics3D :> Style[g, TextAlignment -> Center]] &; but I hate using $Post. $\endgroup$
    – Michael E2
    Apr 5, 2023 at 16:53
  • $\begingroup$ Oh that works fine! I'll put it in the initialization cell. Thanks for teaching me about $Post. If you post your code as an answer, I'll accept it. $\endgroup$ Apr 5, 2023 at 17:30


Your Answer

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

Browse other questions tagged or ask your own question.