I created a grid g1
with Grid[]
and then a separate grid g2
. g1
and g2
have same number of columns. How to put the rows of g2
at the end of g1
purely using front-end? I tried to highlight g2
, Ctrl+C, and move my curser to various positions in g1
and Ctrl+V. But it always resulted in something not desirable such as the entire g2
being copied into a cell of g1
. Any suggestions?
3 Answers
Say you have two Grid
:
First place the cursor at the end of the last row:
Then use menu command Add Row (please note the short-cut) to add as many rows as g2
has:
Then copy g2
by dragging from the items (not by select the whole grid or cell!):
Then select all empty rows you just created in g1
and paste:
-
$\begingroup$ Can you think of any way to do this without creating as many rows as needed manually? I cannot think of a way myself, though I'm hoping one exists. +1 nevertheless. $\endgroup$ Jun 6, 2013 at 6:09
-
$\begingroup$ @Mr.Wizard Thanks. I can't think of one for now, so I would not suggest doing this for large grid.. I'll try it after lunch. Maybe something related to
ArrayFlatten
.. $\endgroup$– SilviaJun 6, 2013 at 6:16 -
$\begingroup$ @Silvia's solution is acceptable for my problem at hand. But in general, having to click once for each new row needed seems rather bad. $\endgroup$– qazwsxJun 6, 2013 at 6:35
-
$\begingroup$ @red3y3 To make it feeling (slightly) better, you can press the short-cut instead of click the menu. But still, this is very annoy. $\endgroup$– SilviaJun 6, 2013 at 6:51
-
1$\begingroup$ @Mr.Wizard I give up.. I think it's too complicated FE programming for a not-so-useful function.. $\endgroup$– SilviaJun 6, 2013 at 9:14
Here is another approach: define a function which can combine two grids preserving the union of their options.
rows = Partition[Range[5 3], 3];
g1 = Grid[rows[[;; 3]], Frame -> All]
g2 = Grid[rows[[4 ;;]], Frame -> All]
JoinGrids[Grid[data1 : {__}, opts1 : ___],
Grid[data2 : {__}, opts2 : ___]] :=
Grid[Join[data1, data2], Sequence @@ Union[{opts1, opts2}]]
JoinGrids[g1, g2]
JoinGrids[g2, g1]
g3 = Grid[rows[[4 ;;, ;; 2]], ItemStyle -> Red]
JoinGrids[g2, g3]
Note that the first argument (not including options to Grid) is a 'matrix' (that is a List
of Lists in Mathematica).
Given the following example Grids:
Grid[
{{a11, a12, a13},
{a21, a22, a23},
{a31, a32, a33}}
]
Grid[
{{b11, b12, b13},
{b21, b22, b23},
{b31, b32, b33}}
]
(Note that I have spread the syntax for each Grid over several lines using a keyboard return, but each Grid expression should be contained within a single notebook cell; see the brackets off to the right in the Front End.)
You should place a comma after the last 'row' of your first 'matrix', like so:
Grid[
{{a11, a12, a13},
{a21, a22, a23},
{a31, a32, a33} , }
]
Then you copy the rows from your second Grid, being careful not to copy the outer curly braces, like so:
You then paste that copied set of lists ('rows' if you prefer) after the comma in your first Grid:
Grid[
{{a11, a12, a13},
{a21, a22, a23},
{a31, a32, a33},
{b11, b12, b13},
{b21, b22, b23},
{b31, b32, b33}}
]
With a shift-enter to evaluate the cell, you should have a nice Grid,
which you can then decorate with options to Grid
.
-
$\begingroup$ That's not what i meant. I want to operate on the resultant grids, not the defining code. $\endgroup$– qazwsxJun 6, 2013 at 6:31
g1 = Grid[{{a, b}, {c, d}}, Frame -> All]
,g2 = Grid[{{w, x}, {y, z}}, Frame -> All]
, and theng3=Grid[g1[[1]]~Join~g2[[1]], Frame -> All]
? $\endgroup$