Take the 2-minute tour ×
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
    
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
    
@Nasser, just noticed a number of updates to your post. Hope the answer i just posted addresses most of them. –  kguler Dec 28 '12 at 13:00

1 Answer 1

up vote 4 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.