Is it possible to have automatic rounding of numbers in a table?
Say that I have this, made in the usual way with a tabular environment:
pi | 3.14592654
e | 2.7182818284
phi | 1.6180339887
Can I control how many significant digits are shown without truncating the numbers manually myself?
So for example, if I need four significant digits, the numbers should appear as
pi | 3.1459
e | 2.7183
phi | 1.6180
Bonus points for actually rounding the numbers according to the usual rules without simply truncating them.
I understand this is probably non-trivial, so here's a relaxed version that will also work in my circumstances (all numbers have one and the same precision and character count):
(How) Can I control how many characters are rendered in a column of a table?
So if I define the text in the columns as:
\begin{tabular} % some black magic column definition
text & alongword\\
text & anotherlongword\\
text & morelongwords\\
\end{tabular}
I'd like to get something like:
text along
text anoth
text morel
I know there are non-TeX ways to do this, and I will probably resolve to writing a script if all else fails, but I'm curious whether there's a way to do it solely with TeX & friends.




numprintis very nice! It has a lot other useful stuff that will certainly come in handy. Thanks! – Martin Tapankov Jan 17 '11 at 12:37siunitx, use{header}. For other simpler packages, use\multicolumn{1}{c}{...}– Leo Liu Aug 03 '13 at 05:07numprintmakes it non-trivial to align the numbers in the columns of the table. The way I see itsiunitxworks in a less intrusive way (no preamble declarations other than the package declaration) and the number alignment just works without tweaks, as in the solution provided by @Mico below or in this other answer. – Pablo Adames May 21 '20 at 01:08