2

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?

1
  • dcolumn is defined via the array package \newcolumntype feature. Commented May 17, 2013 at 22:06

1 Answer 1

3

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}
2
  • amazing, that's what is needed. how can you set the width of the right column?
    – pml
    Commented May 17, 2013 at 22:35
  • @pml you set it by the values in the D colunm D{.}{.}{10}{5} makes it wide enough for 10 digits to the left of a . and 5 digits to the right. It doesn't matter if there are any entries like that it is just a space specification really. Commented May 17, 2013 at 22:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .