Re: Creating Nested GridBoxes
- To: mathgroup at smc.vnet.net
- Subject: [mg43414] Re: Creating Nested GridBoxes
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Fri, 29 Aug 2003 07:16:27 -0400 (EDT)
- Organization: The University of Western Australia
- References: <bht3nc$n2t$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <bht3nc$n2t$1 at smc.vnet.net>, bghiggins at ucdavis.edu (Brian Higgins) wrote: > I am interested in using GridBoxes to create a table that has row > headings and column headings . The headings should not have the same > style or background as the table. Here is a simple example of what I > am trying to do. First , I create my table > > box1 = StyleBox[ GridBox[{{a, b, d, e}, {f, g, h, i}, {j, k, l , m}}, > RowLines -> True, ColumnLines -> True, GridFrame -> True], > Background -> RGBColor[1, 1, 0]]; > > Here are the column headings: > > columnbox = StyleBox[ GridBox[{{1, 2, 3, 4}}, RowLines -> False, > ColumnLines -> False, GridFrame -> False], Background -> > RGBColor[1, 1, 1]]; > > Now if I combine these two sets of Gridboxes I get the desired result > > DisplayForm[GridBox[{{columnbox}, {box1}}]] > > The difficulty I have is adding the row headings > > rowbox = StyleBox[ GridBox[Transpose[{{" ",1, 2, 3}}], RowLines -> > False, ColumnLines -> False,GridFrame -> False], Background -> > RGBColor[1, 1, 1]]; > > DisplayForm[GridBox[{{rowbox},{GridBox[{{columnbox}, {box1}}]}}]] > > which does not give the desired result. Here is one way to do what you have requested: rowbox = GridBox[Transpose[{{" ", 1, 2, 3}}]]; columnbox = GridBox[{{1, 2, 3, 4}}]; box1 = StyleBox[GridBox[{{a, b, d, e},{f, g, h, i},{j, k, l, m}}, RowLines -> True, ColumnLines -> True, GridFrame -> True], Background -> RGBColor[1, 1, 0]]]; DisplayForm[GridBox[{{"", columnbox}, {rowbox, box1}}]] The problem with this approach, I think, is that there is no simple way to force the row and column headings to be aligned with the rows and columns of box1. This is especially important if the elements in the matrix are of different widths. Another approach (for which the headings must have the same style or background as the table) is mat = {{a, b, d, e}, {f, g, h, i}, {j, k, l, m}}; top = {{1, 2, 3, 4}}; side = Transpose[{{1, 2, 3}}]; corner = {{""}}; << LinearAlgebra` DisplayForm[GridBox[BlockMatrix[{{corner, top}, {side, mat}}], RowLines -> {1, 0}, ColumnLines -> {1, 0}, GridFrame -> True]] Personally, I think this approach is preferable because alignment is automatic, and I think that it looks quite neat. Cheers, Paul -- Paul Abbott Phone: +61 8 9380 2734 School of Physics, M013 Fax: +61 8 9380 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul at physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul