views:

37

answers:

1

I have a latex document that is part of an automated system. So I cannot use fixed widths for the table as the inputs are uncertain.

\begin{tabular}[t]{|l|@{\hfill}r@{ }|c|@{ }l|}
\textbf{\langComponent} & \multicolumn{3}{c}{
\textbf{\shortstack{\leftresultsheader}}
} 
\DTLforeach{resultstableA}{\colA=componentA,\colB=amountfracA,\colC=pmsymbolA,\colD=uncertA}{\\{\colA}&{\colB}&{\colC}&{\colD}}
\DTLforeach{resultstableB}{\colE=componentB,\colF=amountfracB,\colG=pmsymbolB,\colH=uncertB}{\\{\colE}&{\colF}&{\colG}&{\colH}}
\end{tabular}

How can I have the last 3 columns (rcl, which display as a result, a plusminus symbol, and an uncertainty) be all centrally aligned as a group underneath the multicoumn header that spans those 3 columns?

A: 

You could take a look at the packages dcolumn or siunitx (of which I'm the author). I think in either case you'll need to first loop through the database to find the size of the largest number (i.e. how many digits before and after the decimal place). A simple hard-coded siunitx example would be

\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}
\begin{tabular}{S[separate-uncertainty,table-format=4.2(2)]}
  {A header} \\
  1.23(45)   \\
  6789.10(1) \\
\end{tabular}
\end{document}
Joseph Wright