# Table formatting: best practices regarding code sample format

Often, when editing other people's answers and questions, we have to deal with non-formatted tables, as people justifiably don't know how to type those in the text boxes and keep the table formatting. Currently, I usually encode the tables in the code sample format, such as this:

n Left Center Right 1 0.24 1 125 2 -1 189 -8 3 -20 2000 1+10i

Becomes this:

n Left Center Right
1 0.24 1      125
2 -1   189    -8
3 -20  2000   1+10i


Now, that looks like a misuse of the code formatting, but it's at least readable and promptly copyable. I was looking around the MathJax tutorial at Math.SE and got around this part about arrays formatting, which is another possibility and I regard has been used previously on CV.

Basically, this code:

$$\begin{array}{c|lcr} n & \text{Left} & \text{Center} & \text{Right} \\ \hline 1 & 0.24 & 1 & 125 \\ 2 & -1 & 189 & -8 \\ 3 & -20 & 2000 & 1+10i \end{array}$$


Generates this table:

$$\begin{array}{c|lcr} n & \text{Left} & \text{Center} & \text{Right} \\ \hline 1 & 0.24 & 1 & 125 \\ 2 & -1 & 189 & -8 \\ 3 & -20 & 2000 & 1+10i \end{array}$$

Which looks much better but is harder to copy.

What's the best practice regarding table formatting then? Also, am I misusing the code formatting? I see I'm not the first to bring up MathJax arrays (see Have Latex tables stopped working?).

• I tend to use code formatting for tables of values that might be further processed and, when I have the time, $\TeX$ formatting to present certain kinds of information in a clearer manner. A good example of that is the table in stats.stackexchange.com/a/225403/919 which benefited from omitting details in the middle: it was intended to illustrate a pattern, not to convey results. In effect, that table served more as a graphic constructed from text and numbers. – whuber Aug 4 '16 at 18:09
• Note that you don't need the dollar signs ($$...$$) when your MathJax starts & ends with \begin{} ... \end{}. – gung - Reinstate Monica Aug 4 '16 at 20:15

While the MathJax/LaTeX table formatting is nice, it's a lot of work. I would not ask anyone to do it as a matter of routine. The added value is small, despite the prettier appearance.

If we spend a lot of time making perfect tables, fewer posts will be edited. Better several readable posts than one perfect one.

In this instance, I think best is the enemy of the good.

• Absolutely, plus it must be much harder to copy-paste a MathJax table into a script. – amoeba Aug 3 '16 at 22:06
• In general, nice presentation beats nasty, but a lot of work doesn't beat a little. Hence I agree with this line. I'd add that to me tables of numbers that aren't aligned in columns on the decimal point are unattractive, not to say innumerate, even in some flavour of TeX or LaTeX. Three fields, before, the decimal point and after, are one way to do that. You may know a better way. – Nick Cox Aug 4 '16 at 6:28

I would like to express an active preference for the "code format" tables over Latex ones in most circumstances, particularly if the table has been aligned properly.

The ease of copying tables of data into a spreadsheet or script for further analysis or graphing is a huge advantage and something I regularly make use of. I have occasionally had to copy Latex tables into a spreadsheet or script and found it a significant inconvenience. (Slightly easier to do it from the Latex source rather than just copying directly what's rendered in the browser, but there is still quite a lot of formatting to change.)

Latex tables are sometimes superior, particularly if you know that the table contains a lot of textual description or certainly isn't something someone is going to want to input into a script, e.g.

$$\begin{array}{c|ccc} \times & \text{-ve} & 0 & \text{+ve} \\ \hline \text{-ve} & \text{+ve} & 0 & \text{-ve} \\ 0 & 0 & 0 & 0 \\ \text{+ve} & \text{-ve} & 0 & \text{+ve} \end{array}$$

... or for which a "clean" layout or the ability to use Latex typesetting would be helpful, e.g.

$$\begin{array}{c|cc} & x & y \\ \hline x & x^2 & xy \\ y & xy & y^2 \\ \end{array}$$

• +1. Excellent advice. – amoeba Aug 4 '16 at 11:42