Message Boards Message Boards

Centering a Grid between page margins

Posted 11 years ago

I have several sets of data that I want to display in columnar form. Each set of data is in a Table and will display with different number of columns.

Is there an easy way to center each set of data so it appears centered between the page margins?

So far, I display each set using something like Grid Grid Table.... The inner Grid creates the columnar form, and the outer Grid displays the column form in the center position. I end up with something like this:

enter image description here

But even this requires that I manually size the Spacings of the outer Grid. I'd rather avoid the outer Grid and just center the columnar form between the page margins.

Thanks for any suggestions.

POSTED BY: Glenn Carlson
Posted 11 years ago

I'm still looking for a way to do this with one Grid, but a partial solution is to use ItemSize to avoid manually sizing Spacings in outer Grid.

(* Eight data triplets  *)
data1 := {{0, -2, 14632971213167*^-14}, {0, -1, -84548187169114*^-14}, 
          {0, 0, -37563603672040*^-13}, {0, 1, 33855169168385*^-13}, 
          {0, 2, -95791963387872*^-14}, {0, 3, 15772038513228*^-14}, 
          {0, 4, -16616417199501*^-15}, {0, 5, 81214629983568*^-17}}

(* Create a table of the data w/ header row *)
tbl01 := Prepend[
  Table[{i, data1[[i]][[1]], data1[[i]][[2]], 
    NumberForm[N[data1[[i]][[3]], 14], 14, 
     ExponentFunction -> (If[(# + 1) == 0, "", (# + 1)] &), 
     DigitBlock -> 3, 
     NumberSeparator -> "[ThickSpace][ThickSpace]"], i + 4, 
    data1[[i + 4]][[1]], data1[[i + 4]][[2]], 
    NumberForm[N[data1[[i + 4]][[3]], 14], 14, 
     ExponentFunction -> (If[(# + 1) == 0, "", (# + 1)] &), 
     DigitBlock -> 3, 
     NumberSeparator -> "[ThickSpace][ThickSpace]"]}, {i, 
    4}], {Item["i", Alignment -> Center], 
   Item["!(*SubscriptBox[(I), (i)])", Alignment -> Center], 
   Item["!(*SubscriptBox[(J), (i)])", Alignment -> Center], 
   Item["!(*SubscriptBox[(n), (i)])", Alignment -> Center], 
   Item["i", Alignment -> Center], 
   Item["!(*SubscriptBox[(I), (i)])", Alignment -> Center], 
   Item["!(*SubscriptBox[(J), (i)])", Alignment -> Center], 
   Item["!(*SubscriptBox[(n), (i)])", Alignment -> Center]}]

(* Display the data as a grid *)
tbl02 = Grid[tbl01, Alignment -> {{{Center, Right, Right, "."}}}, 
  Spacings -> {{0, 1, 1, 1, 3, 1, 1, 1}, Automatic}, 
  ItemStyle -> {Directive[FontFamily -> "Times", 
     FontSize -> 14], {Italic}}, 
  Dividers -> {None, {1 -> Directive[Thickness[1]], 2 -> True, 
     6 -> True}}]

(* Center between margins by displaying as a grid in a grid *)
Grid[{{tbl02}}, ItemSize -> Scaled[1.0]]

The result is

enter image description here

POSTED BY: Glenn Carlson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract