[comp.text] Printing tables in LaTeX

m1swd00@fed.frb.gov (Sean W. Doyle) (04/05/89)

Two LaTeX table formatting questions:

1. 	Is there an easy way to format numbers in a table aligned vertically
	by decimal point? 
2. 	Can numbers be easily `rounded' in LaTeX? 

In some ways I'm looking for a format command similar to (forgive me!) FORTRAN.

For example, how would I print a table of the following sort:

	1.234	1.2345	1.2
	 .323	 .7890	 .1
       -2.009	 .0902   .3


Thanks!
	

 Sean Doyle    
 Board of Governors of the Federal Reserve System 
 Washington, DC 20551  (202) 452-2352            
 uucp: uunet!fed!m1swd00 , internet: sdoyle@fed.frb.gov

akk2@uhura.cc.rochester.edu (Atul Kacker) (04/07/89)

In article <412@mqws2.fed.FRB.GOV> m1swd00@fed.frb.gov (Sean W. Doyle) writes:
>
>Two LaTeX table formatting questions:
>
>1. 	Is there an easy way to format numbers in a table aligned vertically
>	by decimal point? 
>
>For example, how would I print a table of the following sort:
>
>	1.234	1.2345	1.2
>	 .323	 .7890	 .1
>       -2.009	 .0902   .3
>
I'm sure there are other ways to do it, but what I ended up using in my
thesis, was a combination of "tables" macro (available from the latex-style
collection at sun.soe.clarkson.edu) and the following kludge from The
TeXbook (p.241).  Basically what you do is to take a character (? in this
case) and make it active and then use it to manually align decimal points.
Crude, but hey, it works.
----------------------------
\documentstyle[tables]{report}
\begin{document}
% ------------ kludge for aligning decimal points
\newdimen\digitwidth
\setbox0=\hbox{\rm0}
\digitwidth=\wd0
\catcode`?=\active
\def?{\kern\digitwidth}
% ----------- use the table environment in LaTeX
\begin{table}[p]
\begintable  % the begintable and endtable are for the tables macros
339.1 | 275.4 | 1220 | ?0.67 | 23.0 | 0.19 | 292.2 | 3.76 \cr
339.8 | 274.6 | 1190 | ?3.10 | 23.0 | 0.19 | 292.1 | 3.85 \cr
347.1 | 277.0 | 1150 | 20.75 | 22.9 | 0.22 | 298.4 | 3.53 \cr
348.3 | 276.1 | 1150 | 28.20 | 22.9 | 0.23 | 299.1 | 3.51 \cr
352.9 | 291.8 | 1160 | ?0.24 | 22.0 | 0.18 | 308.9 | 2.95 \cr
357.4 | 287.1 | 1160 | 19.90 | 23.0 | 0.22 | 309.4 | 3.11
\endtable
\end{table}
\end{document}
----------------------------------