1
$\begingroup$

I have a table that looks something like this

With[{func = Pane[Style[#, LineIndent -> 0], ImageMargins -> 10] &},
 Grid[{{func@"SHORT", func@"LONGLONGLONG", func@"A",
    Item["There is a lot of text in here that might linebreak and \
thus force this grid line to be taller", ItemSize -> Fit]},
   {"Text here as well", SpanFromLeft}},
  Frame -> All,
  Background -> LightBlue,
  Spacings -> {0, 0}]
 ]

I like that the size of the first elements in the first row is proportional to the length of the string. I am happy with the way the grid resizes when I'm decreasing the length of the window.

Now, I want to have some of the items in the first row to have a gradient fill background. I am having trouble getting the items' original size and behaviour when resizing more or less the same... This is as close as I've been able to get:

Module[{func},
 func[text_, size_: Automatic] :=
  Item[Graphics[{
    Rotate[
     Raster[{Range[50]/50}, {Scaled[{0, 0}], Scaled[{1, 1}]},
      ColorFunction -> (Blend[{LightBlue, Blue}, #] &)],
     90 Degree],
    Inset[Style[text, LineIndent -> 0], Automatic,
     Automatic, {2, Automatic}]},
   ImagePadding -> 0,
   ImageMargins -> 0,
   PlotRangePadding -> 0,
   PlotRangeClipping -> False,
   PlotRange -> All,
   AspectRatio -> Full,
   ImageSize -> {size, 45}
   ]];
 Grid[{{"SHORT", func@"LONGLONGLONG", func@"A",
    Item[func[
      "There is a lot of text in here that might linebreak and thus \
force this grid line to be taller", Scaled[1]], ItemSize -> Fit]},
   {"Text here as well", SpanFromLeft}},
  Frame -> All,
  Background -> LightBlue,
  Spacings -> {0, 0}]
 ]

The problem here is that LONGLONGLONG and A have the same size and the second approach forces me to specify a fixed height that doesn't change when resizing the grid. Ideally, the height of the first row would be as dynamic as in the first example -- fits nicely around the text with a large window and increases accordingly with a narrower window, at the same time resizing the gradient graphic to fill the whole grid item... in essence, the code I have at the moment doesn't quite behave the way the first grid does.

How can I get the second grid to behave the same way as the first one when resizing the notebook window?

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.