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?

  • dcolumn is defined via the array package \newcolumntype feature. – David Carlisle May 17 '13 at 22:06
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}
  • amazing, that's what is needed. how can you set the width of the right column? – pml May 17 '13 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. – David Carlisle May 17 '13 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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