4
$\begingroup$

I am trying to export a data table in PNG format. I evaluated

Ptr = {{1, 5, 10, 20, 30}};

Ttr = {{300, 300, 300, 300, 300}};

P = {{382, 390, 400, 420, 440}};

T = {{}};
m = Join[Transpose[Ttr], Transpose[Ptr], Transpose[P], Transpose[T], 2];
firstRow = {{"", "Ttr(K)", "Ptr(kPa)", "P(kPa)", "T(K)"}};
mainRows = Join[Transpose[{{"n=11", "n=12", "n=13", "n=14", "n=15"}}], m, 2];

t = Join[firstRow, mainRows];
grid = 
  Text @
    Grid[t, 
      Dividers -> {2 -> True, 2 ->  True}, 
      ItemStyle -> {Bold, Red},
      Spacings -> {2, 1}];

 SetDirectory[NotebookDirectory[]];
 Export["grid.PNG", grid,  ImageResolution -> 400, 
 Background -> None];

Unfortunately, I get the image shown below in which the top side and left side are not so well exported!

enter image description here

I tried to solve this problem with Spacing. But it didn't work. In addition, when I exported the table as a PDF file, it worked, but I wish the image in PNG format or JPG format.

$\endgroup$
2
  • $\begingroup$ Make the horizontal spacing in Grid wider... $\endgroup$ Commented Feb 7, 2018 at 12:53
  • $\begingroup$ I change that even to Spacings -> {7, 7} but it was not fruitful!!! $\endgroup$ Commented Feb 7, 2018 at 13:05

1 Answer 1

5
$\begingroup$

May be this helps:

grid = Rasterize[
   Text@Grid[t, Dividers -> {2 -> True, 2 -> True}, 
     ItemStyle -> {Bold, Red}, Spacings -> {2, 1}], RasterSize -> 300];

SetDirectory[NotebookDirectory[]];
Export["grid.PNG", grid, ImageSize -> 800];

enter image description here

$\endgroup$

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.