Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

When I create a Grid using the menu, as follows:

Mathematica graphics

and then start to add data, I'd like to make the alignment to be left and not center which is the default

Mathematica graphics

There is no option to change this when creating new Grid as one can see:

Mathematica graphics

If I try to change the alignment in code by making new variable like this

   data2 = Grid[data, Frame -> All, Alignment -> Left]

and then use data2 from now on, I find it is no longer possible to add rows/columns to data2.

Question: How to control alignment of Grid/Matrix when it is created using the menu? Is there a way to do that afterwords while keeping the functionality of adding rows/column?

I am using V9 on windows 7.

update

adding a row, after making new copy with correct alignment, does actually work. The cursor has to be on the row itself, and not outside, and not by selecting the whole grid. This screen shot shows the correct way. Again, make sure the cursor is inside the grid, at the row where the new row needs to be inserted.

Mathematica graphics

Update 12/27/12

Just wanted to point out the difference between making a Grid using the menu, vs. the command Grid.

When using the menu to create a Grid, the data added to the Grid can be access as a matrix, directly. But when creating the Grid in code using the command itself, the data is wrapped by the Grid, and one needs an extra dimension to access the data. This picture explains:

Mathematica graphics

So, this shows that it would have been better to be able to make the Grid using the menu. But becuase it is missing the alignment option, one has to use the command itself, but then one must remember to add the extra dimension now each time.

share|improve this question
The short-cuts Ctrl+Enter to add rows and Ctrl+, to add columns don't work? – kguler Dec 27 '12 at 17:12
@kguler, I tried that before, but was putting the cursor outside the matrix, and tried when I selected the whole matrix. When I tried now, but first putting the cursor on the row itself, then ctrl+row, now it worked. So, just did not know the cursor has to be inside on the row. I added note above on this for future reader. If you want to add this as answer, I can accept it. thanks. – Nasser Dec 27 '12 at 17:44
If I select the bottom right placeholder (from your update) and then hit ctrl-comma I get an extra column. Problem solved? – Sjoerd C. de Vries Dec 27 '12 at 20:08
@SjoerdC.deVries, another great hint. Thanks. I just wish the alignment option was there when using the menu to make a Grid. But now with the ability to add row/column and still use the visual grid for inputting data, I am ok with it. If you like to put this as an answer I can close this as resolved using this as an accepted work around for the missing feature in the menu. – Nasser Dec 27 '12 at 21:38
btw, I just found that there is a big different between making the same Grid using the menu vs. using the command Grid. But easy to work around. I am adding an update to clarify. – Nasser Dec 27 '12 at 22:04
show 1 more comment

1 Answer

up vote 2 down vote accepted

If you are not specifically set on creating an input grid using the Insert menu you can manually create the Box form that you want, including whatever alignment parameters you require. For example:

grid[dims__] :=
 Cell[BoxData[GridBox[
     ConstantArray["\[Placeholder]", {dims}],
     GridBoxAlignment -> {"Columns" -> {{Left}}}
   ]], "Input"] // CellPrint

Use:

grid[2, 3]

Mathematica graphics

And after entering values:

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.