gaufler
![Screenshot 2021-06-19 093600.jpg](/image?hash=6caf63cdb1192dfe74b424a8df8c964ee9ce2425634360e17fb07b0e963db3a8)
Can someone help me out in designing this table ? My table building skills are dull and I am having a hard time making this. Please help!
Top Answer
user 3.14159
It is rather easy to generate such a table, one option is to use `tabularx`. But it is also a bit cumbersome. It becomes slightly less cumbersome and more interesting if one lets (La)TeX do the computations.
```
\documentclass{article}
\usepackage{tabularx}
\usepackage{xfp}
\begin{document}
\begin{table}
\centering
\newcommand\dDigit[1]{\edef\myi{1}%
\edef\mydigits{9}\ifnum#1>1\relax
\loop
\edef\myi{\the\numexpr\myi+1}%
\edef\mydigits{\mydigits9}%
\ifnum\myi<#1\repeat\fi}%
\newcommand\mytableline[4][]{%
\dDigit{#3}%
$#2=\edef\mysum{\fpeval{#2}}%
\mysum\equiv\fpeval{trunc(\mysum-(\mydigits*trunc(\mysum/\mydigits,0)),0)}\pmod\mydigits$
& $#3$ & $\fpeval{18/#3}$ & #4}%
\begin{tabularx}{0.95\textwidth}{|X|c|c|c|}
\hline
& $m$ & $n$ & $c_n$\\
\hline
\hline
\mytableline{0+5+2+6+3+1+5+7+8+9+4+7+3+6+8+4+2+1}{1}{9}\\
\hline
\mytableline{05+26+31+57+89+47+36+84+21}{2}{4}\\
\hline
\mytableline{052+631+578+947+368+421}{3}{3}\\
\hline
\mytableline{052631+578947+368421}{6}{1}\\
\hline
\mytableline{052631578+947368421}{9}{1}\\
\hline
\end{tabularx}
\end{table}
\end{document}
```
![Screen Shot 2021-06-18 at 10.16.11 PM.png](/image?hash=bccfb2b11db0666da7d998cf289e94b3ebd11583e1325609e6cdc89e2f643da2)
Some comments:
1. The lines are generated from some rather minimal input. (One could also let LaTeX split the digits but then it is harder to adjust the code for other purposes, so I thought the present version is a reasonable compromise.)
2. Nowadays the vertical and horizontal lines in tables are not too popular, you may want to use `booktabs` instead.
3. Since you do not provide any document I had to select a document class and width. As long as you load `tabularx` and `xfp` you should be able to use this in your document but may have to adjust the width etc..