Graphics, Figures & TablesProblem with dcolumn

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
crunch
Posts: 1
Joined: Tue Nov 23, 2010 3:14 pm

Problem with dcolumn

Post by crunch »

Hey,

i got a small problem with dcolumn. The third and fourth column shifted to the right. Any ideas?

THX,
Dominik


Code: Select all

\documentclass[a4paper]{article}
\usepackage{dcolumn}
\begin{document}
	

\clearpage
\begin{table}
\caption{\textbf{Überschrift}}

\begin{tabular}{lD{.}{.}{5}D{.}{.}{5}D{.}{.}{2}D{.}{.}{2}}
%D{ sep.tex }{ sep.dvi }{ decimal places }

\hline\hline

&\multicolumn{2}{c}{Peters et al} 
& \multicolumn{1}{c}{Peter Pan} 
& \multicolumn{1}{c}{Franz Müller}\\

&\multicolumn{1}{c}{(1999)} 
&\multicolumn{1}{c}{(2004)} 
& \multicolumn{1}{c}{(2009)} 
& \multicolumn{1}{c}{(2009)}\\

\hline
Alter
& -0.01**
& -0.01**
&  0.00
&  0.00\\

& (0.00)
& (0.00)
& (0.00)
& (0.00)\\

Klasse
&  0.02
& 0.02
&  0.12**
& 0.12**
\\

& (0.05)
& (0.04)
& (0.05)
& (0.05)
\\

Gesundheit
& -0.57***
& -0.63***
& -0.62***
& -0.62***
\\

& (0.06)
& (0.05)
& (0.06)
& (0.06)
\\

\hline

Variance component&  0.87     &    1.10   & 0.45 &  0.43    \\
Log-Likelihood&   \multicolumn{1}{c}{-1399}   &     \multicolumn{1}{c}{-2147} & \multicolumn{1}{c}{-1313}    & \multicolumn{1}{c}{-1311}    \\
No. of individuals& \multicolumn{1}{c}{2868}   &    \multicolumn{1}{c}{4824}   & \multicolumn{1}{c}{3208}  & \multicolumn{1}{c}{3208}     \\
No. of countries& \multicolumn{1}{c}{15}   & \multicolumn{1}{c}{23 (?)}   & \multicolumn{1}{c}{19}      & \multicolumn{1}{c}{19}       \\
\hline\hline
\end{tabular}
\smallskip
\end{table}



\end{document}
Attachments
tabellen2.pdf
tabular
(45.45 KiB) Downloaded 190 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Problem with dcolumn

Post by localghost »

It seems that the number alignment needs to be adjusted by declaring another number format. See code below for an approach and some suggestions for minor tweaks.

Code: Select all

\documentclass[11pt,a4paper,ngerman]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{booktabs,dcolumn}

\newcolumntype{d}[1]{D{.}{.}{#1}}   % D{sep.tex}{sep.dvi}{number.format}

\begin{document}
  \begin{table}[!ht]
    \caption{Überschrift}\label{tab:tabelle}
    \begin{tabular}{l*4{d{5.5}}}\toprule
      &\multicolumn{2}{c}{Peters et al} & \multicolumn{1}{c}{Peter Pan} & \multicolumn{1}{c}{Franz Müller} \\
      &\multicolumn{1}{c}{(1999)} &\multicolumn{1}{c}{(2004)} & \multicolumn{1}{c}{(2009)} & \multicolumn{1}{c}{(2009)}\\ \midrule
      Alter      & -0.01**  & -0.01**  & 0.00     & 0.00 \\
                 & (0.00)   & (0.00)   & (0.00)   & (0.00) \\\addlinespace
      Klasse     & 0.02     & 0.02     & 0.12**   & 0.12** \\
                 & (0.05)   & (0.04)   & (0.05)   & (0.05) \\\addlinespace
      Gesundheit & -0.57*** & -0.63*** & -0.62*** & -0.62*** \\
                 & (0.06)   & (0.05)   & (0.06)   & (0.06) \\ \midrule
      Variance component & 0.87 & 1.10 & 0.45 & 0.43 \\
      Log-Likelihood & -1399 & -2147 & -1313 & -1311 \\
      No. of individuals & 2868 & 4824 & 3208 & 3208 \\
      No. of countries & 15 & 23 (?) & 19 & 19 \\ \bottomrule
    \end{tabular}
  \end{table}
\end{document}
Note the newly declared column type in the preamble. The dcolumn manual has the details. In this context it is also worth to take a look at the array manual.


Best regards and welcome to the board
Thorsten
Post Reply