# Numbering entries in a table by column

I'm trying to make a large table that has four columns, with two columns that are numbered incrementally. Note that the real table will have around 40 numbered entries.

Here's roughly the desired behavior and a kludgy MWE, using two counters with the totcount package (rowA and rowB, note the use of \setcounter{rowB}{\totvalue{rowA}}).

\documentclass[11pt,letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{totcount}
\usepackage{array}

\newtotcounter{rowA}
\newcommand\rowA{\stepcounter{rowA}{\bf \arabic{rowA}.~}}

\newcounter{rowB}
\newcommand\rowB{\stepcounter{rowB}{\bf \arabic{rowB}.~}}

\renewcommand{\arraystretch}{2}

\begin{document}
\setcounter{rowB}{\totvalue{rowA}}
$\begin{array}{*2{>{\displaystyle}l}*2{>{\displaystyle}l}} f(t) & \mathcal{L}\{f\}(s) & f(t) & \mathcal{L}\{f\}(s) \\ \hline \rowA e^{at} & \frac{1}{s-a} & \rowB t^n & \frac{n!}{s^{n+1}} \\ \rowA \sin(bt) & \frac{b}{s^2 + b^2} & \rowB u(t-a), \, a\geq 0 & \frac{e^{-as}}{s}\\ \rowA \cos(bt) & \frac{s}{s^2+b^2} & \rowB \delta(t-a), \, a \geq 0 & e^{-as} \end{array}$
\end{document}


### Questions

1. Is there a less kludgy way to do this? Ideally something that only requires one counter and numbering command?
2. I'm particularly annoyed with this solution in that I have to decide what information ends up in each column at the start---very WYSIWYG/non-TeX. I would love to be able to enter the formulas as a two column table and then wrap with multicols. I'm trying to do this with longtable and repeated headers, but no joy thus far.
• \bf is a deprecated command, just as side-note – user31729 Apr 23 '17 at 22:39

I addressed the first question here, by applying automatic stepping in the column types (defining new column types, for this)

The reason why the A and B types are using \text{\bfseries ...} is that \bfseries is not allowed in math mode, which is active there.

\documentclass[11pt,letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{totcount}
\usepackage{array}

\newtotcounter{rowA}
\newcounter{rowB}

\newcolumntype{A}{>{\stepcounter{rowA}{\text{\bfseries\therowA.~}}}l}
\newcolumntype{B}{>{\stepcounter{rowB}{\text{\bfseries\therowB.~}}}l}

\newcolumntype{M}{>{\displaystyle}l}

\renewcommand{\arraystretch}{2}

\begin{document}
\setcounter{rowB}{\totvalue{rowA}}
$\begin{array}{AMBM} \multicolumn{1}{M}{f(t)} & \multicolumn{1}{M}{\mathcal{L}\{f\}(s)} & \multicolumn{1}{M}{f(t)} & \multicolumn{1}{M}{\mathcal{L}\{f\}(s)} \\ \hline e^{at} & \frac{1}{s-a} & t^n & \frac{n!}{s^{n+1}} \\ \sin(bt) & \frac{b}{s^2 + b^2} & u(t-a), \, a\geq 0 & \frac{e^{-as}}{s}\\ \cos(bt) & \frac{s}{s^2+b^2} & \delta(t-a), \, a \geq 0 & e^{-as} \\ & & & \\ % Fake line \end{array}$
\end{document}


Way with only one counter

\documentclass[11pt,letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{totcount}
\usepackage{array}

\newtotcounter{rowA}

\newcolumntype{A}{>{\displaystyle\stepcounter{rowA}{\mathbf{\therowA.~}}}l}
\makeatletter
% Using one counter only: add the current value of \rowA and the total counter value -- this will give the 'rowB'
\newcolumntype{B}{>{\displaystyle\mathbf{\@arabic{\numexpr \c@rowA + \totvalue{rowA}}.~}}l}
\makeatother

\newcolumntype{M}{>{\displaystyle}l}

\renewcommand{\arraystretch}{2}

\begin{document}
$\begin{array}{AMBM} \multicolumn{1}{M}{f(t)} & \multicolumn{1}{M}{\mathcal{L}\{f\}(s)} & \multicolumn{1}{M}{f(t)} & \multicolumn{1}{M}{\mathcal{L}\{f\}(s)} \\ \hline e^{at} & \frac{1}{s-a} & t^n & \frac{n!}{s^{n+1}} \\ \sin(bt) & \frac{b}{s^2 + b^2} & u(t-a), \, a\geq 0 & \frac{e^{-as}}{s}\\ \cos(bt) & \frac{s}{s^2+b^2} & \delta(t-a), \, a \geq 0 & e^{-as} \\ \frac{1}{t} f(t) & \int_s^\infty F(u) ~\mathrm{d} u & \frac{1}{\sqrt{t}} & \frac{\sqrt{\pi}}{\sqrt{s}}\\ \end{array}$
\end{document}


• Ah, very slick--I was unaware of the newcolumntype command. Any thoughts on the wrapping inside multicols? Am I just asking for a world of hurt with that approach? – erfink Apr 23 '17 at 22:55
• With longtable and multicols? No, I don't think that's possible. You can use 'ordinary' tables, but the splitting has to be done manually in order to provide vertical alignment in multicols of the starting line, but it would not look very nice for other rows since they don't have the same height. – user31729 Apr 23 '17 at 22:59
• Okay, thank you very much! I'll give it a day to see if any other quality answers show up; currently leaning towards accepting your answer. – erfink Apr 23 '17 at 23:01
• Minor quibble--Columns 1 and 3 aren't landing in displaystyle (e.g. add in another row as \frac{1}{t} f(t) & \int_s^\infty F(u) ~\mathrm{d} u & \frac{1}{\sqrt{t}} & \frac{\sqrt{\pi}}{\sqrt{s}} – erfink Apr 23 '17 at 23:15
• @erfink: Yes, I accidentally removed the \displaystyle for A and B types. See the update at the end, please – user31729 Apr 23 '17 at 23:23