[Tex/LaTex] tabular with “centered” and “flushright” entries

dcolumnhorizontal alignmenttables

I need to typeset a tabular with the following requirement:

  • the head of a tabular should be center in the column

  • the entries should be flushright and (more or less) center in the the
    column

like in the following example

|   -head of a column-   |
--------------------------
|           120          |
|         42001          |

I can do this by making each entry of the same width (say with \phantom) and then centering the column, but as a tabular are fairly large it's a lot of tedious work.

I'm aware of the existance of dcolumn package (and answer given here https://tex.stackexchange.com/a/73702/7313), however I don't know how to use it together with array package and features it provides (\newcolumntype mostly)

Is there any wiser way to do this?

Best Answer

enter image description here

\documentclass{article}

\usepackage{dcolumn}

\newcolumntype{C}{>{\centering}p{1cm}}
\newcolumntype{E}{D{.}{.}{5.0}}

\begin{document}

\begin{tabular}{C E}
xxx & \multicolumn{1}{c}{\textbf{head of col}}\\
y y y  & 120\\
z z z z z  & 42001
\end{tabular}

\end{document}
Related Question