I'm from another Stack Exchange site where we've just had MathJax enabled. There's a table in this answer that looks like this (actual decimals just typed in for the example), which looks rather pretty, except the rows and columns are unlabelled:
\begin{array}{r|lll}
& 0 & 1 & 2 \\
\hline
0 & 0.125 & 0.250 & 0.168 \\
1 & 0.125 & 0.250 & 0.168 \\
2 & 0.125 & 0.250 & 0.168
\end{array}
If I want to label the headings and columns, my attempts go awry due to stretching out the first column:
\begin{array}{r|lll}
& \text{number of foo} \\
\text{number of bar} & 0 & 1 & 2 \\
\hline
... clearly that's not the way to do it. Googling has turned up \multicolumn
, but that's a thing for tables which aren't available in the Stack's MathJax.
I've considered I could just use a bunch of spacing to finagle the label into just the right position. It looks nice, but I don't know if there's a way I "should" be doing it or could bear in mind for the future:
\,\,\quad\qquad\qquad \text{number of foo} \rightarrow \\
\begin{array}{r|lll}
\text{number of bar} & 0 & 1 & 2 \\
\hline
Is there an appropriate, robust and good-looking way to place a label across a set of columns? I'm open to using an environment other than array, if it does the job of displaying that data in a tabular form and works within our Stack Exchange MathJax environment.