[texhax] Alignment with respect to symbol

Steve Schwartz s.j.schwartz at qmul.ac.uk
Fri Jun 27 14:49:59 CEST 2003


Zacharia

Try this:

\documentclass{article}
\newcommand{\hd}{\hphantom{0}}
\begin{document}
\begin{tabular}{r@{$\pm$}l}
  Value & Err \\ \hline
  10.1\hd  & 13.2\hd \\
  11.23    & 21.27 \\
  3.72 & \hd2.13 \\
\end{tabular}
\end{document}

Obviously you can play with adding spacing aroung the \pm, or even
putting it in its own column and playing with column spacing, right
justify the error, etc. The REAL problem with aligning things on decimal
points is, as the example above, when all the numbers don't have the
same number of digits. I fudge this by adding a phantom zero (all
numeric characters in TeX have the same width; there are 3 phantoms:
\phantom, \vphantom, and \hphantom which insert in the output real, but
empty, boxes having the size of the argument (\phantom), height and zero
width of the argument (\vphantom), or width and zero height (\hphantom).
To make the table slightly more readable in the source, I defined a
shorthand command \hd.

This is a pain to do for a long complicated set of numbers, but works.
I'm sure there are clever ways, but this hack works pretty well. I'd
also suggest reading the ways to insert and control intercolumn aspects
of LaTeX tables (like the @ instruction) in any LaTeX manual.

Steve

On Fri, 2003-06-27 at 13:43, zacharia wrote:
> Phil,
> 
> Thanx for the clue, still I could not nest it in a table enviroment!
> I think, I  wud put more effort......
> 
> Philip G. Ratcliffe wrote:
> 
> >>I have here a table with numbers having the error bar (something like
> >>48.0 $\pm$ 3.2)
> >>Is there any method to align with first decimal, symbol($\pm$) and
> >>second decimal.
> >>or at least some method to align with respect to symbol alone?
> >>    
> >>
> >
> >Try the following example:
> >
> >\documentclass{article}
> >\begin{document}
> >\begin{displaymath}
> >  \begin{array}{r@{\,\pm\,}r}
> >    48.0 &  3.2 \\
> >   153.5 &  0.1 \\
> >     3.0 & 10.0 \\
> >  \end{array}
> >\end{displaymath}
> >\end{document}
> >
> >If you understand the structure, it's easy to see how to align on decimal
> >points.
> >
> >Cheers,  Phil
> >
> >  
> >
> 
> 
> 
> _______________________________________________
> TeX FAQ: http://faq.tug.org/
> Human mailing list managers: postmaster at tug.org
> Automated subscription management: http://tug.org/mailman/listinfo/texhax
-- 
+-----------------------------------------------------------------+
| Steve Schwartz               S.J.Schwartz at qmul.ac.uk            |
| Astronomy Unit                                                  |
| Queen Mary, Univ. of London  Tel: +44 (0)20 7882 5449           |
| Mile End Road                Fax: +44 (0)20 8983 3522           |
| London E1 4NS, UK            URL: www.space-plasma.qmul.ac.uk/  |
+-----------------------------------------------------------------+




More information about the texhax mailing list