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.

How do you insert more columns into Table cells as shown below?

To get to this table, go to File -> New -> Styled Notebook -> Textbook -> New -> Scroll down to the Table Cells.

http://img145.imageshack.us/img145/9009/db931ede98ce459db69ca94.png

share|improve this question
add comment

1 Answer 1

up vote 8 down vote accepted

I guess you would like to keep formatting of the table. The following is programmatic way to do it. For simplicity I will deal with the smallest Table 1.1 in that template.

Click anywhere on the table and press Ctrl+Shift+I on Windows or Command+Shift+I on Mac. The 1st table will turn into the following code:

enter image description here

Ctrl+Shift+I produces so called InputForm of an expression. From the code above it is easy to separate the table-maker part and make a function

tbl[x_] := Grid[x, Alignment -> {{Left, Center}, {Bottom, Top}}, 
  BaseStyle -> {TextJustification -> 0, ParagraphIndent -> 0, FontFamily -> "Times"}, 
    Dividers -> {{False}, {1 -> AbsoluteThickness[2.], 
     2 -> AbsoluteThickness[0.5], -1 -> AbsoluteThickness[0.5]}}, 
    ItemSize -> {Automatic, Automatic}, Spacings -> {10., {1, 0.5}}]

Now you can just use it with arbitrary styles and number of rows or/and columns set by, Style, ConstantArray, Table or similar functions:

tbl[ConstantArray[Style["placeholder", Italic, 18, FontFamily -> "Gabriola"], {6, 3}]]

enter image description here

You now can edit placeholder dummies and then evaluate edited table (press Shift+Enter) to get final result.

If due to any reason you would like to preserve exactly the Textbook styles of table entries, you could use another part of the code you got after Ctrl+Shift+I to define a simplest data structure:

data = {{TextCell["Enter column head here", Italic, Editable -> True],
         TextCell["Enter column head here", Italic, Editable -> True]}, 
        {TextCell["Enter data here", Editable -> True], 
         TextCell["Enter data here", Editable -> True]}};

Define a function for adding columns and/or rows:

newtbl[x_, n_, m_] := Transpose[(#~Join~Table[Last[#], {i, n}]) &@
                                Transpose[x~Join~Table[Last[x], {i, m}]]]

Use it to add, for example, 2 more columns and 7 more rows:

tbl[newtbl[data, 2, 7]]

Select the resulting output cell and choose Top menu >> Format >> Style >> Table. You can even sandwich it now between "table title" and "table note" cells to make it perfect:

enter image description here

share|improve this answer
add comment

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.