Skip to main content
added 127 characters in body
Source Link
Jagra
  • 14.6k
  • 1
  • 39
  • 82

A first thought of how approach the problem.

n = 10;
itemSize = 1.5;
Column[{
  Grid[{
    {"", " Matrix ", ""},
    {"", SpanFromAbove, ""}
    },
   Frame -> All,
   ItemSize -> n/itemSize,
   Alignment -> {Center, Center},
   Dividers -> {False, {False, {2 -> True}}}],
  
  Grid[{
    RandomInteger[n, n],
    RandomInteger[n, n]},
   ItemSize -> itemSize,
   Frame -> None,
   Alignment -> Center]
  },
 Alignment -> Center]

enter image description here

I set up a Column of 2 Grids.

The first, Grid enables you to center your label, "Matrix", and to generate horizontal lines to each side of it using Grid's option, Dividers.

I've set up a variable itemSize = 1.5 and use it in the 2nd Grid to establish a known fixed width for each column in the 2nd Grid.

In the 1st Grid, I set a simple relationship between your n and the 1st Grid's ItemSize option.

You could certainly do this more elegantly and more comprehensively. This works on my machine with n >= 7, but it would benefit from more thought.

Essentially:

  • breakup the problem into smaller bits.
  • control things that matter  (e.g., ItemSize->n/itemSize).
  • establish a relationship between the smaller bits.

If the above looks promising, you could try controlling the ItemSize in the 1st Grid for each of its 3 columns.

A first thought of how approach the problem.

n = 10;
itemSize = 1.5;
Column[{
  Grid[{
    {"", " Matrix ", ""},
    {"", SpanFromAbove, ""}
    },
   Frame -> All,
   ItemSize -> n/itemSize,
   Alignment -> {Center, Center},
   Dividers -> {False, {False, {2 -> True}}}],
  
  Grid[{
    RandomInteger[n, n],
    RandomInteger[n, n]},
   ItemSize -> itemSize,
   Frame -> None,
   Alignment -> Center]
  },
 Alignment -> Center]

enter image description here

I set up a Column of 2 Grids.

The first, Grid enables you to center your label, "Matrix", and to generate horizontal lines to each side of it using Grid's option, Dividers.

I've set up a variable itemSize = 1.5 and use it in the 2nd Grid to establish a known fixed width for each column in the 2nd Grid.

In the 1st Grid, I set a simple relationship between your n and the 1st Grid's ItemSize option.

You could certainly do this more elegantly and more comprehensively. This works on my machine with n >= 7, but it would benefit from more thought.

Essentially:

  • breakup the problem into smaller bits.
  • control things that matter(e.g., itemSize).
  • establish a relationship between the smaller bits.

A first thought of how approach the problem.

n = 10;
itemSize = 1.5;
Column[{
  Grid[{
    {"", " Matrix ", ""},
    {"", SpanFromAbove, ""}
    },
   Frame -> All,
   ItemSize -> n/itemSize,
   Alignment -> {Center, Center},
   Dividers -> {False, {False, {2 -> True}}}],
  
  Grid[{
    RandomInteger[n, n],
    RandomInteger[n, n]},
   ItemSize -> itemSize,
   Frame -> None,
   Alignment -> Center]
  },
 Alignment -> Center]

enter image description here

I set up a Column of 2 Grids.

The first, Grid enables you to center your label, "Matrix", and to generate horizontal lines to each side of it using Grid's option, Dividers.

I've set up a variable itemSize = 1.5 and use it in the 2nd Grid to establish a known fixed width for each column in the 2nd Grid.

In the 1st Grid, I set a simple relationship between your n and the 1st Grid's ItemSize option.

You could certainly do this more elegantly and more comprehensively. This works on my machine with n >= 7, but it would benefit from more thought.

Essentially:

  • breakup the problem into smaller bits.
  • control things that matter  (e.g., ItemSize->n/itemSize).
  • establish a relationship between the smaller bits.

If the above looks promising, you could try controlling the ItemSize in the 1st Grid for each of its 3 columns.

Source Link
Jagra
  • 14.6k
  • 1
  • 39
  • 82

A first thought of how approach the problem.

n = 10;
itemSize = 1.5;
Column[{
  Grid[{
    {"", " Matrix ", ""},
    {"", SpanFromAbove, ""}
    },
   Frame -> All,
   ItemSize -> n/itemSize,
   Alignment -> {Center, Center},
   Dividers -> {False, {False, {2 -> True}}}],
  
  Grid[{
    RandomInteger[n, n],
    RandomInteger[n, n]},
   ItemSize -> itemSize,
   Frame -> None,
   Alignment -> Center]
  },
 Alignment -> Center]

enter image description here

I set up a Column of 2 Grids.

The first, Grid enables you to center your label, "Matrix", and to generate horizontal lines to each side of it using Grid's option, Dividers.

I've set up a variable itemSize = 1.5 and use it in the 2nd Grid to establish a known fixed width for each column in the 2nd Grid.

In the 1st Grid, I set a simple relationship between your n and the 1st Grid's ItemSize option.

You could certainly do this more elegantly and more comprehensively. This works on my machine with n >= 7, but it would benefit from more thought.

Essentially:

  • breakup the problem into smaller bits.
  • control things that matter(e.g., itemSize).
  • establish a relationship between the smaller bits.