List Manipulation: Add
Here is how I would do it:
makeTOC[names_, n_] := Flatten[
Partition[
Thread[{Range@Length@names, names}],
n, n, 1, {}
],
{{2}, {1, 3}}
]
And a few examples:
makeTOC[testNames, 3] //TableForm
makeTOC[testNames, 5] //TableForm
makeTOC[testNames, 8] //TableForm
one another possibility
make list of names
list = ("name_" <> ToString[#]) & /@ Range[13]
Then use Partition
with option UpTo
and then use TableForm
with Heading
nRows=4;
TableForm[Partition[list,UpTo[nRows]],TableHeadings->{Range[nRows],None}]
Multicolumn
is similar to what you are trying to do except that Multicolumn[list, cols]
uses the smallest number of rows so that all elements will be shown. That is, for a given number of columns it balances the entries per column.
makeTOC[nameList_List, nRowsIn_Integer: 5] :=
Multicolumn[testNames, Ceiling[Length[nameList]/nRowsIn]]
testNames = "Name_" <> # & /@ CharacterRange["A", "J"];
makeTOC[testNames, #] & /@ {3, 5, 8, 12} //
Column[#, Spacings -> 2] &