5
$\begingroup$

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)

$\endgroup$
  • $\begingroup$ Specify the ItemSize for the numeric cells, e.g., Item[bbEEDdPercent /. f4g, ItemSize -> {Scaled[.2], Automatic}]? $\endgroup$ – kglr Dec 23 '17 at 18:31
  • 1
    $\begingroup$ or add ItemSize -> {{Scaled[.4], Scaled[.4]}, Automatic} after Frame->All in your posted code. $\endgroup$ – kglr Dec 23 '17 at 18:56
  • $\begingroup$ Try using ImageSize->All, and possibly adjust the Spacings option as well. $\endgroup$ – Carl Woll Dec 23 '17 at 19:15
  • $\begingroup$ @kglr, your second suggestion worked beautifully. I had to tweak the numbers a bit, but that's what I needed. Thanks so much! $\endgroup$ – crlast86 Dec 23 '17 at 20:46
  • $\begingroup$ crlast86, posted the comment as an answer. $\endgroup$ – kglr Dec 23 '17 at 22:50
3
$\begingroup$

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

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – crlast86 Dec 27 '17 at 18:14
  • $\begingroup$ @crlast86, my pleasure. Thank you for the accept. $\endgroup$ – kglr Dec 27 '17 at 19:43
2
$\begingroup$

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

$\endgroup$

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.