[Tex/LaTex] alignment of multicolumn cell

horizontal alignmenttables

Consider this table

\begin{tabular}{lr@{}l}
  Bla & \multicolumn{2}{c}{A $\to$ B} \\
  \hline
  X   & 23.1&* \\
  Y   & 7.5&  
\end{tabular}

which produces

2-by-2 table with headings

The second column heading appears to be left-aligned. What do I have to do to make it centred?

Best Answer

If a multicolumn entry is wider than the columns it spans then TeX's primitive \halign mechanism puts the extra space into the last spanned column, which is rarely what is wanted.

You can put some extra space into the earlier columns so that this does not occur, or here you may be better to use one of the packages for numeric alignment that keeps the numbers in a single column. I have used dcolumn here as I know it, but siunitx is newer with more features.

\documentclass{article}

\usepackage{dcolumn}

\begin{document}

1

\begin{tabular}{lr@{}l}
  Bla & \multicolumn{2}{c}{A $\to$ B} \\
  \hline
  X   & 23.1&* \\
  Y   & 7.5&  
\end{tabular}


2

\begin{tabular}{lr@{}l}
  Bla & \multicolumn{2}{c}{A $\to$ B} \\
  \hline
  X   & \quad23.1&* \\
  Y   & 7.5&  
\end{tabular}

3 (using a text mode * as suggested by @egreg's comment)

\begin{tabular}{lD{.}{.}{2.2}}
  Bla & \multicolumn{1}{c}{A $\to$ B} \\
  \hline
  X   & 23.1\rlap{*} \\
  Y   & 7.5  
\end{tabular}

4 (or using a math mode superscript *)

\begin{tabular}{lD{.}{.}{2.2}}
  Bla & \multicolumn{1}{c}{A $\to$ B} \\
  \hline
  X   & 23.1^{*} \\
  Y   & 7.5  
\end{tabular}

\end{document}

enter image description here