I'm using package numprint
to create a table which automatically formats its columns. However, the table has many columns.
Right now, my table definition looks like this:
\begin{tabular}{l n{2}{3} n{2}{3} n{2}{3} n{2}{3} n{2}{3} n{2}{3} .. etc ..} ..
Using package pgffor
I would like to automate the number of column definitions (because they might differ). I thought of doing this using a \foreach
as follows:
\begin{tabular}{l \foreach \k in {1,...,6}{ n{2}{3} }}
But it doesn't work. It gives an error that extra alignment tab has been changed to ..
, which implies that it can't interpret the output of the for each
loop.
What is the correct way of doing this? (automatically generating the column types)
Best Answer
No
pgffor
package is required for this; just write your table preamble as:The general syntax is:
where
n
is the number of repetitions, and the pattern can be any number ofcolumn specifiers
,@{some code}
, !{some code}
,>{…}
,<{…}
.Some part of this syntax depends on the
array
package – in particular>{…}
,<{…}
and!{…}
.