Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

An alternative is to use $Post to post-process output automatically as it is generated.

For instance, the following outputs anything with the head Graphics in a style "centeredOutput", which could be defined in whatever manner one wants.

centerGraphics[g_Graphics | g_Graphics3D] := CellPrint@ExpressionCell[g, "centeredOutput"]; centerGraphics[x_] := x; $Post = centerGraphics 

One could center the graphics also by wrapping it in Pane:

centerGraphics[g_Graphics | g_Graphics3D] := Pane[g, Alignment -> Center, ImageSize -> Full]; 

Update: From a suggestion by Mr.WizardMr.Wizard, with this definition, formatting the graphics could be handled more gracefully by setting $PrePrint = centerGraphics and $Post =. (or leave $Post unset). Then the value of Out will be the graphics instead of the Pane.

Notes (updated) --

Any existing graphics would have to be reevaluated.

One should be aware that $Post affects the output value. For example, after executing Plot, the head of % would be Cell, if using the first definition of centerGraphics.

One can circumvent $Post by wrapping the graphics in a head that does not affect typesetting. For instance, Defer@Evaluate@Plot[Sin[x], {x, 0, 10}] would be printed in a normal "Output" cell but the graphics will still be centered.

Because of this, if one wishes to Deploy graphics, one might want to add a rule to centerGraphics to handle Deploy. For example, centerGraphics[g : Deploy[Graphics[__]] | ...] := ...

One need not create a special style. One can set options directly in ExpressionCell, such as with this body for the definition of centerGraphics:

CellPrint@ExpressionCell[g, "Output", TextAlignment -> Center] 

An alternative is to use $Post to post-process output automatically as it is generated.

For instance, the following outputs anything with the head Graphics in a style "centeredOutput", which could be defined in whatever manner one wants.

centerGraphics[g_Graphics | g_Graphics3D] := CellPrint@ExpressionCell[g, "centeredOutput"]; centerGraphics[x_] := x; $Post = centerGraphics 

One could center the graphics also by wrapping it in Pane:

centerGraphics[g_Graphics | g_Graphics3D] := Pane[g, Alignment -> Center, ImageSize -> Full]; 

Update: From a suggestion by Mr.Wizard, with this definition, formatting the graphics could be handled more gracefully by setting $PrePrint = centerGraphics and $Post =. (or leave $Post unset). Then the value of Out will be the graphics instead of the Pane.

Notes (updated) --

Any existing graphics would have to be reevaluated.

One should be aware that $Post affects the output value. For example, after executing Plot, the head of % would be Cell, if using the first definition of centerGraphics.

One can circumvent $Post by wrapping the graphics in a head that does not affect typesetting. For instance, Defer@Evaluate@Plot[Sin[x], {x, 0, 10}] would be printed in a normal "Output" cell but the graphics will still be centered.

Because of this, if one wishes to Deploy graphics, one might want to add a rule to centerGraphics to handle Deploy. For example, centerGraphics[g : Deploy[Graphics[__]] | ...] := ...

One need not create a special style. One can set options directly in ExpressionCell, such as with this body for the definition of centerGraphics:

CellPrint@ExpressionCell[g, "Output", TextAlignment -> Center] 

An alternative is to use $Post to post-process output automatically as it is generated.

For instance, the following outputs anything with the head Graphics in a style "centeredOutput", which could be defined in whatever manner one wants.

centerGraphics[g_Graphics | g_Graphics3D] := CellPrint@ExpressionCell[g, "centeredOutput"]; centerGraphics[x_] := x; $Post = centerGraphics 

One could center the graphics also by wrapping it in Pane:

centerGraphics[g_Graphics | g_Graphics3D] := Pane[g, Alignment -> Center, ImageSize -> Full]; 

Update: From a suggestion by Mr.Wizard, with this definition, formatting the graphics could be handled more gracefully by setting $PrePrint = centerGraphics and $Post =. (or leave $Post unset). Then the value of Out will be the graphics instead of the Pane.

Notes (updated) --

Any existing graphics would have to be reevaluated.

One should be aware that $Post affects the output value. For example, after executing Plot, the head of % would be Cell, if using the first definition of centerGraphics.

One can circumvent $Post by wrapping the graphics in a head that does not affect typesetting. For instance, Defer@Evaluate@Plot[Sin[x], {x, 0, 10}] would be printed in a normal "Output" cell but the graphics will still be centered.

Because of this, if one wishes to Deploy graphics, one might want to add a rule to centerGraphics to handle Deploy. For example, centerGraphics[g : Deploy[Graphics[__]] | ...] := ...

One need not create a special style. One can set options directly in ExpressionCell, such as with this body for the definition of centerGraphics:

CellPrint@ExpressionCell[g, "Output", TextAlignment -> Center] 
Added alternative
Source Link
Michael E2
  • 258.7k
  • 21
  • 370
  • 830

An alternative is to use $Post to post-process output automatically as it is generated.

For instance, the following outputs anything with the head Graphics in a style "centeredOutput", which could be defined in whatever manner one wants.

centerGraphics[g_Graphics | g_Graphics3D] := CellPrint@ExpressionCell[g, "centeredOutput"]; centerGraphics[x_] := x; $Post = centerGraphics 

One could center the graphics also by wrapping it in Pane:

centerGraphics[g_Graphics | g_Graphics3D] := Pane[g, Alignment -> Center, ImageSize -> Full]; 

Notes (updated) --Update: From a suggestion by Mr.Wizard, with this definition, formatting the graphics could be handled more gracefully by setting $PrePrint = centerGraphics and $Post =. (or leave $Post unset). Then the value of Out will be the graphics instead of the Pane.

Notes (updated) --

Any existing graphics would have to be reevaluated.

One should be aware that $Post affects the output value. For example, after executing Plot, the head of % would be Cell, if using the first definition of centerGraphics.

One can circumvent $Post by wrapping the graphics in a head that does not affect typesetting. For instance, Defer@Evaluate@Plot[Sin[x], {x, 0, 10}] would be printed in a normal "Output" cell but the graphics will still be centered.

Because of this, if one wishes to Deploy graphics, one might want to add a rule to centerGraphics to handle Deploy. For example, centerGraphics[g : Deploy[Graphics[__]] | ...] := ...

One need not create a special style. One can set options directly in ExpressionCell, such as with this body for the definition of centerGraphics:

CellPrint@ExpressionCell[g, "Output", TextAlignment -> Center] 

An alternative is to use $Post to post-process output automatically as it is generated.

For instance, the following outputs anything with the head Graphics in a style "centeredOutput", which could be defined in whatever manner one wants.

centerGraphics[g_Graphics | g_Graphics3D] := CellPrint@ExpressionCell[g, "centeredOutput"]; centerGraphics[x_] := x; $Post = centerGraphics 

One could center the graphics also by wrapping it in Pane:

centerGraphics[g_Graphics | g_Graphics3D] := Pane[g, Alignment -> Center, ImageSize -> Full]; 

Notes (updated) --

Any existing graphics would have to be reevaluated.

One should be aware that $Post affects the output value. For example, after executing Plot, the head of % would be Cell, if using the first definition of centerGraphics.

One can circumvent $Post by wrapping the graphics in a head that does not affect typesetting. For instance, Defer@Evaluate@Plot[Sin[x], {x, 0, 10}] would be printed in a normal "Output" cell.

Because of this, if one wishes to Deploy graphics, one might want to add a rule to centerGraphics to handle Deploy. For example, centerGraphics[g : Deploy[Graphics[__]] | ...] := ...

One need not create a special style. One can set options directly in ExpressionCell, such as with this body for the definition of centerGraphics:

CellPrint@ExpressionCell[g, "Output", TextAlignment -> Center] 

An alternative is to use $Post to post-process output automatically as it is generated.

For instance, the following outputs anything with the head Graphics in a style "centeredOutput", which could be defined in whatever manner one wants.

centerGraphics[g_Graphics | g_Graphics3D] := CellPrint@ExpressionCell[g, "centeredOutput"]; centerGraphics[x_] := x; $Post = centerGraphics 

One could center the graphics also by wrapping it in Pane:

centerGraphics[g_Graphics | g_Graphics3D] := Pane[g, Alignment -> Center, ImageSize -> Full]; 

Update: From a suggestion by Mr.Wizard, with this definition, formatting the graphics could be handled more gracefully by setting $PrePrint = centerGraphics and $Post =. (or leave $Post unset). Then the value of Out will be the graphics instead of the Pane.

Notes (updated) --

Any existing graphics would have to be reevaluated.

One should be aware that $Post affects the output value. For example, after executing Plot, the head of % would be Cell, if using the first definition of centerGraphics.

One can circumvent $Post by wrapping the graphics in a head that does not affect typesetting. For instance, Defer@Evaluate@Plot[Sin[x], {x, 0, 10}] would be printed in a normal "Output" cell but the graphics will still be centered.

Because of this, if one wishes to Deploy graphics, one might want to add a rule to centerGraphics to handle Deploy. For example, centerGraphics[g : Deploy[Graphics[__]] | ...] := ...

One need not create a special style. One can set options directly in ExpressionCell, such as with this body for the definition of centerGraphics:

CellPrint@ExpressionCell[g, "Output", TextAlignment -> Center] 
Updated notes
Source Link
Michael E2
  • 258.7k
  • 21
  • 370
  • 830

An alternative is to use $Post to post-process output automatically as it is generated.

For instance, the following outputs anything with the head Graphics in a style "centeredOutput", which could be defined in whatever manner one wants.

centerGraphics[g_Graphics | g_Graphics3D] := CellPrint@ExpressionCell[g, "centeredOutput"]; centerGraphics[x_] := x; $Post = centerGraphics 

One could center the graphics also by wrapping it in Pane:

centerGraphics[g_Graphics | g_Graphics3D] := Pane[g, Alignment -> Center, ImageSize -> Full]; 

Notes (updated) --

Any existing graphics would have to be reevaluated.

One should be aware that $Post affects the output value. For example, after executing Plot, the head of % would be Cell, if using the first definition of centerGraphics.

One can circumvent $Post by wrapping the graphics in a head that does not affect typesetting. For instance, Defer@Evaluate@Plot[Sin[x], {x, 0, 10}] would be printed in a normal "Output" cell.

Because of this, if one wishes to Deploy graphics, one might want to add a rule to centerGraphics to handle Deploy. For example, centerGraphics[g : Deploy[Graphics[__]] | ...] := ...

One need not create a special style. One can set options directly in ExpressionCell, such as with this body for the definition of centerGraphics:

CellPrint@ExpressionCell[g, "Output", TextAlignment -> Center] 

An alternative is to use $Post to post-process output automatically as it is generated.

For instance, the following outputs anything with the head Graphics in a style "centeredOutput", which could be defined in whatever manner one wants.

centerGraphics[g_Graphics | g_Graphics3D] := CellPrint@ExpressionCell[g, "centeredOutput"]; centerGraphics[x_] := x; $Post = centerGraphics 

One could center the graphics also by wrapping it in Pane:

centerGraphics[g_Graphics | g_Graphics3D] := Pane[g, Alignment -> Center, ImageSize -> Full]; 

Notes --

Any existing graphics would have to be reevaluated.

One should be aware that $Post affects the output value. For example, after executing Plot, the head of % would be Cell, if using the first definition of centerGraphics.

An alternative is to use $Post to post-process output automatically as it is generated.

For instance, the following outputs anything with the head Graphics in a style "centeredOutput", which could be defined in whatever manner one wants.

centerGraphics[g_Graphics | g_Graphics3D] := CellPrint@ExpressionCell[g, "centeredOutput"]; centerGraphics[x_] := x; $Post = centerGraphics 

One could center the graphics also by wrapping it in Pane:

centerGraphics[g_Graphics | g_Graphics3D] := Pane[g, Alignment -> Center, ImageSize -> Full]; 

Notes (updated) --

Any existing graphics would have to be reevaluated.

One should be aware that $Post affects the output value. For example, after executing Plot, the head of % would be Cell, if using the first definition of centerGraphics.

One can circumvent $Post by wrapping the graphics in a head that does not affect typesetting. For instance, Defer@Evaluate@Plot[Sin[x], {x, 0, 10}] would be printed in a normal "Output" cell.

Because of this, if one wishes to Deploy graphics, one might want to add a rule to centerGraphics to handle Deploy. For example, centerGraphics[g : Deploy[Graphics[__]] | ...] := ...

One need not create a special style. One can set options directly in ExpressionCell, such as with this body for the definition of centerGraphics:

CellPrint@ExpressionCell[g, "Output", TextAlignment -> Center] 
Source Link
Michael E2
  • 258.7k
  • 21
  • 370
  • 830
Loading