4
$\begingroup$

I am having problems with white spaces in lists displayed in Grid. The problem is that white spaces have less height and width compared to cells that contain text. I also tried none, None, None[], null, Null, Null[],nothing, Nothing. " " seems to be the only solution that is not visible. Spacings->{2,2} seems to be relative not absolute. it only adds padding to what is already there. how can I define constant height and width for all cells? and is there a better way to describe white space other than string " "?

b={
{" "," ",38," "," "," "},
{" "," "," "," ",35," "},
{" ",19," "," "," "," "},
{" ",30," ",46," "," "},
{" "," "," "," "," "," "},
{" "," "," ",52," "," "}
};
Grid[b,Frame->All]
$\endgroup$
5
$\begingroup$

Replace " " with Invisible[38]:

Row[{Grid[b, Frame -> All], 
  Grid[b /. " " -> Invisible[38], Frame -> All]}, 
 Spacer[10]]

enter image description here

Row[{Grid[b, Frame -> All, Spacings -> {2, 2}], 
  Grid[b /. " " -> Invisible[38], Frame -> All, Spacings -> {2, 2}]}, 
 Spacer[10]]

enter image description here

Alternatively, use the option ItemSize:

Grid[b, Spacings -> {2, 2}, Frame -> All, ItemSize -> {All, 1}]

enter image description here

or the option ColumnsEqual:

Grid[b, Spacings -> {2, 2}, Frame -> All, ColumnsEqual -> True]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ Grid[b/. " " -> Invisible[10],Spacings->{2,2},Frame->All] works but Grid[b/. " " -> Invisible[0],Spacings->{2,2},Frame->All] has problems $\endgroup$ – acacia Dec 27 '20 at 3:21
  • $\begingroup$ @acacia, added an example with the option Spacings->{2,2} . $\endgroup$ – kglr Dec 27 '20 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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