Suppose I have a table with 20 columns that should all be centered. Is there a way to declare the alignment without literally counting out 20 c's? Something like c{20} might be the syntax. I feel like I saw this once, but I can't find a reference anywhere.

  • Use the array package, and write the specifiers as {*{20}{c}} instead of {ccc…cc}. – Bernard Jul 21 '14 at 19:20
  • 1
    @Bernard: There is no need for array here, although it is a good addition to any document. – Werner Jul 21 '14 at 19:21
  • @Werner: ? I thought it was defined in array. Never checked though. – Bernard Jul 21 '14 at 19:22
  • @Bernard: Then check. :) – Werner Jul 21 '14 at 19:25
  • @Werner: 'f course, I trust you. I just meant never thought of checking:). – Bernard Jul 21 '14 at 19:28

Replication of column specifications is done using a *{<num>}{<col spec>} interface, which should repeat <col spec> a total of <num> times:

  % tabular content

will produce a table of 20 columns, each one centred. To add vertical column rules (which you should never do), you can use

  % tabular content

Note how the replication only includes a single right-side vertical rule with a single left-side rule at the beginning. One could also have used *{20}{|c}|.

  • The second form behaves slightly more oddly with \multicolumn? – cfr Jul 22 '14 at 2:23
  • 1
    @cfr: Yes; this is because of the insertion of the rules. I forget which (left/right), but they are associated with that particular column. – Werner Jul 22 '14 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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