[Tex/LaTex] typesetting long lists of numbers – is automatic tabling possible

automationtables

I have quite a lot of lists of numbers I need to put into my document. I am not sure how best to typeset them. Inspired by reading Add \midrule Every 5 Lines Automatically the other day, I sort of wondered whether it's possible to use a tabular environment and automatically generate newlines every n numbers, where I could vary n – right now I have just manually created a table, but I want to change n and now I have to go through and move all the \\ and insert extra &… I have absolutely no idea where to begin with this idea though! Here's my current table:

\documentclass[12pt, a4paper, oneside, fleqn]{report}
\usepackage{geometry}
\geometry{
  top=2.5cm,
  left=3.5cm,
  bottom=2.5cm,
  right=2.5cm,
  includehead,
  headheight=28pt,
  headsep=18pt,
  showframe,
}

\usepackage{siunitx}
\usepackage{array,booktabs}


\begin{document}


  \begin{tabular}{ @{} *{10}{S[table-format=4]} @{} } 
  16&   38&  49&  51&  55&  57&  59&  61&  63&  66  \\
  70&   72&  74&  79&  81&  83&  85&  87&  89&  92  \\
  95&   97&  99& 101& 104& 106& 109& 111& 113& 116 \\
  119& 122& 125& 128& 131& 133& 135& 138& 141& 144  \\
  146& 148& 151& 154& 157& 159& 161& 163& 167& 170 \\
  173& 176& 179& 180& 185& 187& 193& 199& 205& 207 \\
  210& 212& 214& 217& 219& 222& 224& 226& 230& 232 \\
  236& 239& 242& 243& 246& 249& 252& 254& 260& 262 \\
  265& 267& 269& 275& 280& 282& 294& 296& 299& 303 \\
  306& 323& 327& 329& 335& 345& 347& 350& 354& 356 \\
  360& 366& 371& 373& 375& 377& 379& 381& 383& 386 \\
  389& 398& 401& 404& 407& 410& 414& 416& 426& 428 \\
  432& 434& 439& 445& 457& 515& 546& 552& 559& 566 \\
  571& 573& 646& 662& 668& 756& 867& 906& 921& 1027 \\
  1046& 1121& 1133& 1191& 1194& 1271& 1479& 1509& 1513& 1521 \\
  1536& 1574& 1579& 1585& 1587& 1626& 1639& 1643& 1652& 1658 \\
  1671& 1786& 1805& 1884& 1991& 2019& 2094& 2119& 2213& 2239 \\
  2245& 2271& 2321& 2398& 2701& 2741& 2819& 2889& 2907& 2910 \\
  2919& 2939& 2944& 2948& 2951& 2958& 2977& 2985& 2988& 2991 \\
  2993& 3002& 3008& 3014& 3027& 3029& 3036& 3047& 3049& 3053 \\
  3058& 3064& 3069& 3087& 3093& 3098& 3105& 3107& 3110& 3127 \\
  3136& 3151& 3160& 3165& 3168& 3175& 3178& 3207& 3228& 3244 \\
  3248& 3252& 3256& 3263& 3281& 3303& 3309& 3312& 3322& 3339 \\
  3375& 3378& 3411& 3438& 3440& 3442& 3444& 3446& 3448& 3450 \\
  3452& 3454& 3458& 3467& 3476& 3484& 3491& 3497& 3499& 3504 \\
  3506& 3509& 3518& 3522& 3527& 3540& 3555& 3575& 3577& 3580 \\
  3582& 3586& 3589& 3599& 3653& 3658& 3661& 3943& 4032& 5130 \\
  5368& 5371& 5379& 5381& 5383& 5397& 5399& 5401& 5403& 5405 \\
  5455& 5480& 5483& 5485& 5492& 5502& 5507& 5509& 5517& 5558 \\
  5988& 5992& 5994& 6003& 6350& 6463& 6601& 6962& 6980& 6982 \\
  6985& 6987& 6989& 6991& 6993& 6995& 6997& 7267& 7269& 7424 \\
  7426& 7428& 7885& 8007
\end{tabular}  

\end{document}

I am not even sure this is the best way to display a list of numbers – does it even look OK? I think it looks marginally better than the randomly spaced list I had before I inserted the tabular, and a lot better than the comma separated list I tried.

Best Answer

enter image description here

\documentclass[12pt, a4paper, oneside, fleqn]{report}
\usepackage{geometry}
\geometry{
  top=2.5cm,
  left=3.5cm,
  bottom=2.5cm,
  right=2.5cm,
  includehead,
  headheight=28pt,
  headsep=18pt,
  showframe,
}

\def\mylist#1 {\ifx!#1\else\makebox[4em][r]{#1} \expandafter\mylist\fi}


\begin{document}


\begin{flushleft}
  \mylist
  16   38  49  51  55  57  59  61  63  66  
  70   72  74  79  81  83  85  87  89  92  
  95   97  99 101 104 106 109 111 113 116 
  119 122 125 128 131 133 135 138 141 144  
  146 148 151 154 157 159 161 163 167 170 
  173 176 179 180 185 187 193 199 205 207 
  210 212 214 217 219 222 224 226 230 232 
  236 239 242 243 246 249 252 254 260 262 
  265 267 269 275 280 282 294 296 299 303 
  306 323 327 329 335 345 347 350 354 356 
  360 366 371 373 375 377 379 381 383 386 
  389 398 401 404 407 410 414 416 426 428 
  432 434 439 445 457 515 546 552 559 566 
  571 573 646 662 668 756 867 906 921 1027 
  1046 1121 1133 1191 1194 1271 1479 1509 1513 1521 
  1536 1574 1579 1585 1587 1626 1639 1643 1652 1658 
  1671 1786 1805 1884 1991 2019 2094 2119 2213 2239 
  2245 2271 2321 2398 2701 2741 2819 2889 2907 2910 
  2919 2939 2944 2948 2951 2958 2977 2985 2988 2991 
  2993 3002 3008 3014 3027 3029 3036 3047 3049 3053 
  3058 3064 3069 3087 3093 3098 3105 3107 3110 3127 
  3136 3151 3160 3165 3168 3175 3178 3207 3228 3244 
  3248 3252 3256 3263 3281 3303 3309 3312 3322 3339 
  3375 3378 3411 3438 3440 3442 3444 3446 3448 3450 
  3452 3454 3458 3467 3476 3484 3491 3497 3499 3504 
  3506 3509 3518 3522 3527 3540 3555 3575 3577 3580 
  3582 3586 3589 3599 3653 3658 3661 3943 4032 5130 
  5368 5371 5379 5381 5383 5397 5399 5401 5403 5405 
  5455 5480 5483 5485 5492 5502 5507 5509 5517 5558 
  5988 5992 5994 6003 6350 6463 6601 6962 6980 6982 
  6985 6987 6989 6991 6993 6995 6997 7267 7269 7424 
  7426 7428 7885 8007 !
\end{flushleft}

\end{document}
Related Question