7
$\begingroup$

I have a series of highly formatted grids of information (text, values, tiny plots, etc) that are formatted by a function. The grids are of different widths and heights as Grid is automatically sizing them to their contexts. They look good in Mathematica.

The problem comes when exporting. They will be exported to PNG images for use outside of Mathematica. If I just Export the images look as the grids on the screen.

g = Grid@{{"Apples", "Oranges", "Peaches", "Pears"}, {100, 200, 300, 
    400}}

Export[FileNameJoin[{NotebookDirectory[], "good.png"}], g]

enter image description here

However, the image is too small for the intended use. Therefore, I export with Magnify.

Export[FileNameJoin[{NotebookDirectory[], "bad.png"}], Magnify[g, 2]]

enter image description here

As can be seen above, when this is done the grid adjusts its width to the width of the notebook window which results in the loss of layout. You can see this by evaluating Magnify[g, 2] and then slowly decreasing the width of the notebook window.

What option setting on Grid can be set to stop it resizing itself to the notebook window width? I believe Magnify on such a grid would not result in the resizing which would give the expected exported image.

I believe this might be some Style or Text option that I can put in the BaseStyle option of Grid but I have not been able to find it as yet. But this may not be the correct approach.

If the grid is wider then the width of the window the horizontal scrollbar would be used to view the portion wider than the window. This behavior would be similar to how wide Dataset objects are displayed.

$\endgroup$
0

2 Answers 2

3
$\begingroup$

ItemSize -> Full:

g2 = Grid[{{"Apples", "Oranges", "Peaches", "Pears"}, {100, 200, 300, 400}},
  ItemSize -> Full]

Import@Export["/tmp/foo.png", Magnify[g, 5]]    (* OP *)

Mathematica graphics

Import@Export["/tmp/foo.png", Magnify[g2, 10]]  (* ItemSize -> Full *)

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ So simple. How did I miss this? $\endgroup$
    – Edmund
    May 1, 2017 at 13:55
  • $\begingroup$ @Edmund Zillions of Grid and GridBox options. :) $\endgroup$
    – Michael E2
    May 1, 2017 at 14:02
3
$\begingroup$

The option ItemSize -> All seems to work. The notebook looks like this

notebook

and the exported PNG like this

grid

$\endgroup$

Your Answer

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

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