6

I have a grid I've created with the first row set up as the title to the grid. The problem I'm having is that when the title is wider than the following rows need to be, Mathematica extends the final column of the lower rows to be wider. I'd really like to tell it to space the lower rows evenly, but I can't seem to figure out how to do it. I've been fiddling around with ItemSize, but I just can't seem to land on the correct solution. I have included a code sample and the output I'm getting from it here.

With[
 {bbEEDdPercent = "31.2%", bbEeDdPercent = "62.5%"},
 f4g = x_String :> Style[Text[x], 25];
 Grid[{
   {Style[UnderBar[Text["Dilute-factored Chocolate"]], 35, Bold], 
    SpanFromLeft}
   , {"bbEEDd" /. f4g, bbEEDdImage, bbEEDdPercent /. f4g}
   , {"bbEeDd" /. f4g, bbEeDdImage, bbEeDdPercent /. f4g}
   }, Alignment -> {Center, Center}, Frame -> All]]

results of above code (images included when I ran it)

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
kgrafton
  • 263
  • 1
  • 7

2 Answers2

4

You can use option ItemSize in several ways.

With[{bbEEDdPercent = "31.2%", bbEeDdPercent = "62.5%"}, 
 f4g = x_String :> Style[Text[x], 25];
 Grid[{{Style[UnderBar[Text["Dilute-factored Chocolate"]], 35, Bold], 
    SpanFromLeft}, {"bbEEDd" /. f4g, bbEEDdImage, 
    bbEEDdPercent /. f4g}, {"bbEeDd" /. f4g, bbEeDdImage, 
    bbEeDdPercent /. f4g}},
  Alignment -> {Center, Center}, Frame -> All, 
  ItemSize -> {{3 -> Scaled[.1]}}]]

enter image description here

ItemSize -> {{3 -> 6}} gives

enter image description here

ItemSize -> {{1 -> 12, 2 -> 10}} gives

enter image description here

Note: Somehow, in version 9, specifying item sizes for all three columns doesn't give the expected result. However if you modify the first gird entry to

Style[UnderBar[Text["Dilute-factored Chocolate"]], 35, Bold, LineBreakWithin -> False]

then you can use a setting like {{Scaled[.2], Scaled[.3], Scaled[.1]}} to get the desired result:

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
  • I ended up using ItemSize->{{3->6}} and LineBreakWithin->False and the combination of these two fixed my issue. I'll need to do some more reading on why that worked in case I ever have the problem again. Thank you so much! – kgrafton Dec 27 '17 at 18:14
  • @crlast86, my pleasure. Thank you for the accept. – kglr Dec 27 '17 at 19:43
3

The documentation says ItemSize -> All makes all the columns evenly spaced. Use this for the column size.

With[
 {
  bbEEDdPercent = "31.2%",
  bbEeDdPercent = "62.5%"
  },
 f4g = x_String :> Style[Text[x], 25];

 Grid[{
   {
    Style[UnderBar[Text["Dilute-factored Chocolate"]], 35, Bold], 
    SpanFromLeft, SpanFromLeft
    },
   {"bbEEDd" /. f4g, bbEEDdImage, 
    bbEEDdPercent /. f4g}, {"bbEeDd" /. f4g, bbEeDdImage, 
    bbEeDdPercent /. f4g}
   },
  Alignment -> {Center, Center},
  Frame -> All,
  ItemSize -> {All, Automatic}
  ]
 ]

Mathematica graphics

Jack LaVigne
  • 14,462
  • 2
  • 25
  • 37