Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using the dcolumn package to align cell contents at the decimal seperator. Now in the table header I have a textual description of the column, for example like this:

\begin{tabular}{c|d{4.3}}
  field & \multicolumn{1}{c}{description} \\
  \hline
  a     &    0.55 \\
  b     & 1223.4
\end{tabular}

As you can see I had to wrap this text in multicolumn to make LaTeX happy which somehow is a hack. Is there a more elegant way? Especially for many columns this gets a little cumbersome.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

It's not a hack, it is the correct approach. The dcolumn package works by inserting appropriate code before and after the cell contents to make the alignment work. Using \multicolumn skips insertion of the alignment code, which is exactly what you want.

You could use my siunitx package to do the alignment without using \multicolumn, but it might be overkill for this case:

\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}
\begin{tabular}{cS[table-format = 4.3]}
  \toprule
  field & {Description} \\
  \midrule
  a     &    0.55 \\
  b     & 1223.4 \\
  \bottomrule
\end{tabular}
\end{document}
share|improve this answer
    
I have indeed considered using siunitx instead which can do a lot of useful things, but as you say, it seemed to be overkill in this case. –  fuenfundachtzig Aug 12 '11 at 12:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.