Re: centering a figure
- To: mathgroup at smc.vnet.net
- Subject: [mg21116] Re: centering a figure
- From: "P.J. Hinton" <paulh at wolfram.com>
- Date: Fri, 17 Dec 1999 01:21:14 -0500 (EST)
- Organization: "Wolfram Research, Inc."
- References: <831shi$fiv@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 12 Dec 1999, Henrik Weimer wrote:
> Using Mathematica 4, is there a way to have the Graphics displayed in a
> Cell be automatically centered on the page. I can move graphics around
> manually, but once the window is resized it won;t be centered anymore.
> Ideally, I would like someling like TextAlignment->Center that works for
> graphics.
>
> Any ideas? Thanks!
Use an alternative display function that writes a cell with the graphic
embedded as an inline cell.
centeredGraphicDisplayFunction[
gr : (_Graphics | _Graphics3D | _SurfaceGraphics |
_DensityGraphics | _ContourGraphics)
] :=
Module[
{psstring, cellexpr},
SelectionMove[
EvaluationNotebook[],
After,
EvaluationCell
];
psstring = DisplayString[gr];
cellexpr = Cell[
TextData[
{Cell[GraphicsData["PostScript", psstring]]}
],
"Graphics",
TextAlignment -> Center
];
NotebookWrite[EvaluationNotebook[], cellexpr]
]
Once this is evaluated, you can make use of it by specifying this as the
value of the DisplayFunction option:
Plot[Sin[x], {x, 0, 2Pi}, DisplayFunction ->
centeredGraphicDisplayFunction]
--
P.J. Hinton
Mathematica Programming Group paulh at wolfram.com
Wolfram Research, Inc.
Disclaimer: Opinions expressed herein are those of the author alone.