5
$\begingroup$

That is all:

How can I set the width of columns in a Grid in terms of pixels instead of 'ems'?

To be more precisely, I want to create a grid that is 330 pixels wide, with 3 columns being 110 pixels wide each of them.

This could be a MWE:

Panel[Grid[{{"Hello", "World", "!"}}, Spacings -> 1, ItemSize -> All], ImageSize -> {330, 540}]

In this example, I tried to force the grid to have a width of 330, but I did not suceeded.

I am also asking for the case where you want each column to have a specific different width (in pixels, again). The previous MWE could serve as MWE for this question (without ItemSize -> All, of course).

EDIT: It is not mandatory to use Grid. I just thought it was the best way to show my results.

$\endgroup$
1
  • $\begingroup$ @Kuba I've just reached a very similar solution by my own, just now. Would you like to post yours as an answer? $\endgroup$
    – Vicent
    Commented Sep 16, 2014 at 13:50

1 Answer 1

9
$\begingroup$

Well, it was very easy. I found it by myself, and also @Kuba posted it as a comment (I think it has been deleted, though).

I can get what I want by using Scaled. It does not directly use pixels, but I can get the same results:

Panel[Grid[{{"Hello", "World", "!"}}, 
  Spacings -> 1, 
  ItemSize -> {{Scaled[1/3], Scaled[1/3], Scaled[1/3]}, Automatic}], 
 ImageSize -> {330, 540}]
$\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.