ItemSize >> Properties and Relations
:
- "Controls and graphics will by default expand to fit the available area."
So we can use a graphics object as the title row:
ClearAll[addTitleRow]
addTitleRow[ttl_, lineStyle_: Automatic, textStyle_: Automatic, pos_: {.5, 0}] :=
PadRight[
Prepend[{Graphics[{lineStyle /.
Automatic -> Directive[Gray, Thickness[Tiny]], Line[{{0, 0}, {1, 0}}],
Black, Text[Style[ttl, textStyle /. Automatic -> 14,
Background -> White], pos]},
ImagePadding -> 0, PlotRangePadding -> 0,
ImageSize -> {Scaled[1.03], All}, AspectRatio -> 1/20]}] @ #,
Automatic, SpanFromLeft] &;
Examples:
n = 10;
mat = {RandomInteger[n, n], RandomInteger[n, n]};
Grid[addTitleRow[" matrix "] @ mat,
Alignment -> {Center, Center}, ItemSize -> {3, 1}, Frame -> All]
Grid[addTitleRow[" matrix "] @ mat,
Alignment -> {Center, Center}, ItemSize -> {3, 1}, Frame -> {True, {False, {True}}}]
Grid[addTitleRow[" matrix "] @ mat,
Alignment -> {Center, Center}, ItemSize -> {3, 1}]
Grid[addTitleRow[" matrix ",
Directive[Orange, AbsoluteThickness[12], CapForm["Butt"]],
Directive[Blue, 18], {.15, 0}] @ mat,
Alignment -> {Center, Center}, ItemSize -> {3, 1}, Frame -> All]
Replace Frame -> All
with Frame -> {True, {False, {True}}}
to get
Remove the option Frame -> ..
to get
mat2 = {RandomInteger[n, 2 n], RandomInteger[n, 2 n]};
Grid[addTitleRow[" matrix "] @ mat2,
Alignment -> {Center, Center}, ItemSize -> {2, 1}, Frame -> All]