How can I align the numbers of the table by decimals with dcolumn package?

You declared the d type but did not use it, something like

enter image description here

\documentclass[12pt,a4paper]{article}

% use utf-8 \usepackage[latin1]{inputenc}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{\cdot}{#1}}
\begin{document}
% l*{1}{ccccc} is the same as lccccc and doesn't use d!

\begin{center}
\begin{tabular}{@{}l d{6.0} d{2.3} d{2.3} d{2.0} d{3.0} @{}}
    \multicolumn{6}{c}{Cuadro I}\\
    \multicolumn{6}{c}{Estadísticas descriptivas GEIH} \\
    \hline\hline
\\
\multicolumn{1}{c}{Obs}& 
\multicolumn{1}{c}{Media}&
\multicolumn{1}{c}{\begin{tabular}{@{}c@{}}Desviación\\Estándar\end{tabular}}&
\multicolumn{1}{c}{Min}&
\multicolumn{1}{c}{Máx}\\
    \hline
    Ocupados    &   96703         &  .896&    .306&           0&           1\\
    Años de educación         &  96703          &    10.583&    4.331&           0&          26\\
    Soltero     &  96703          &    .281&     .449&           0&           1\\
    Jefe de hogar  &  96703          &    .435&    .496&           0&           1\\
    Edad       &    96703        &    39.301&    13.824&          18&         100\\
    \hline
    \multicolumn{6}{@{}c@{}}{Ocupados según nivel de estudio}\\
    Ninguno     & 586599            &    .546&    .498&           0&           1\\
    Bachiller   &  586599          &    .203&    .402&           0&           1\\
    Técnico    &  586599          &    .161&    .367&           0&           1\\
    Universitario& 586599           &    .065&    .246&           0&           1\\
    Postgrado   &  586599          &    .000&    .007&           0&           1\\
    \hline
\end{tabular}

\end{center}

\end{document}

but the horizontal rules would look better if you used \midrule from the booktabs package.


Here's how I would present the table, with siunitx. This has several advantages, for instance automatic uniformization of the decimal separator and automatic formatting of large numbers.

Also numbers should always show the integer part and siunitx adds it automatically, if it is absent.

\documentclass[12pt,a4paper]{article}
\usepackage[spanish]{babel}
\usepackage{siunitx,booktabs}

\sisetup{output-decimal-marker={,}}

\begin{document}

\begin{table}[htp]
\centering

\caption{Estadísticas descriptivas GEIH}\label{add-here-a-label}

\medskip

\begin{tabular}{
  @{}
  l
  S[table-format=6.0]
  S[table-format=2.3]
  S[table-format=2.3]
  S[table-format=2.0]
  S[table-format=3.0]
  @{}
}
\toprule
& {Obs} & {Media} & {DE} & {Min} & {Máx} \\
\midrule
Ocupados          &  96703 &   .896 &   .306 &  0 &   1 \\
Años de educación &  96703 & 10.583 &  4.331 &  0 &  26 \\
Soltero           &  96703 &   .281 &   .449 &  0 &   1 \\
Jefe de hogar     &  96703 &   .435 &   .496 &  0 &   1 \\
Edad              &  96703 & 39.301 & 13.824 & 18 & 100 \\
\midrule
\multicolumn{6}{@{}l@{}}{\itshape Ocupados según nivel de estudio} \\
Ninguno           & 586599 &   .546 &   .498 &  0 &   1 \\
Bachiller         & 586599 &   .203 &   .402 &  0 &   1 \\
Técnico           & 586599 &   .161 &   .367 &  0 &   1 \\
Universitario     & 586599 &   .065 &   .246 &  0 &   1 \\
Postgrado         & 586599 &   .000 &   .007 &  0 &   1 \\
\bottomrule
\multicolumn{6}{@{}l@{}}{\footnotesize DE: Desviación Estándar} \\
\end{tabular}

\end{table}

\end{document}

enter image description here

Tags:

Tables

Dcolumn