1

I'm grateful for the advice I got from this community before on how to make columns right aligned in wide tables. But now I cannot domesticate the following table that has 15 columns and some of which contain negative numbers. In addition, I lost the track on how to make the columns right aligned. Suggestions are welcome! Thank you.

\documentclass{book}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc} % Required for inputting international characters

% Paquetes necesarios para las tablas 
\usepackage[flushleft]{threeparttable}
\usepackage{array,calc}
\usepackage{varwidth}
\newcolumntype{Z}{>{\raggedleft\arraybackslash}X}
\usepackage{booktabs,tabularx,ragged2e}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage[margin=1in]{geometry} % choose page size parameters suitably
\addto\captionsspanish{\renewcommand{\tablename}{Tabla}}
%%%

\begin{document}



\begin{table}[th]
\footnotesize
\sf
\caption{\sf Adultos mayores beneficiarios previsionales según grupo de edades y conformación del hogar, en \%}
\label{tab:table32}


\begin{threeparttable}
\begin{tabularx}{\textwidth}{@{} l *{15}{Z} @{}}
\toprule \toprule
& \multicolumn{3}{c}{65 a 69 años}
& \multicolumn{3}{c}{70 a 74 años}
& \multicolumn{3}{c}{75 a 79 años}
& \multicolumn{3}{c}{80 y más años}
& \multicolumn{3}{c}{Total} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-7}
\cmidrule(lr){8-10} \cmidrule(lr){11-13}
\cmidrule(lr){14-16}
& 2003 & 2013 & Var.
& 2003 & 2013 & Var.
& 2003 & 2013 & Var.
& 2003 & 2013 & Var.
& 2003 & 2013 & Var.\\
\midrule
Hogar unipersonal
& 20,8 & 16,3 & $-$4,5
& 19,3 & 23,5 & 4,2
& 30,2 & 29,0 & $-$1,2
& 35,6 & 31,0 & $-$4.6
& 26,8 & 24,7 & $-$2,1 \\
Hogar bipersonal - un solo beneficiario
& 6,3 & 1,8 & $-$4,5
& 17,0 & 1,3 & $-$15,7
& 13,1 & 0,2 & $-$12,9
& 10,0 & 0,7 & $-$9,3
& 11,9 & 1,0 & $-$10,9 \\
Hogar bipersonal - dos beneficiarios
& 10,5 & 23,9 & 13,4
& 20,2 & 26,4 & 6,2
& 15,7 & 29,6 & 13,9
& 13,4 & 26,0 & 12,6
& 15,3 & 26,4 & 11,1 \\
Hogar multipersonal
& 62,4 & 58,0 & $-$4,4
& 43,4 & 48,8 & 5,4
& 41,0 & 41,2 & 0,1
& 40,9 & 42,3 & 1,4
& 46,0 & 48,0 & 1,9 \\
\\
\multicolumn{16}{l}{Adultos mayores en hogares unipersonales\textsuperscript{a}} \\
    Varones  & 28,3 & 28,9 & 0,6
    & 21,1 & 27,8 & 6,7
    & 23,1 & 24,1 & 1,0
    & 22,3 & 23,8 & 1,5
    & 23,3 & 25,7 & 2,5 \\
    Mujeres  & 71,7 & 71,1 & $-$0,6
    & 78,9 & 72,2 & $-$6,7
    & 76,9 & 75,9 & $-$1,0
    & 77,7 & 76,2 & $-$1,5
    & 76,7 & 74,3 & $-$2,5 \\
\bottomrule
\end{tabularx}

\begin{tablenotes}
      \footnotesize
      \smallskip
      \item a: Como porcentaje del total de hogares unipersonales conformados por adultos mayores.
      \item Fuente: Elaboración propia en base a la EPH.
\end{tablenotes}
\end{threeparttable}

\end{table}

\end{document}
3

Your tabular data is mostly numeric, so I would like to suggest that you use siunitx to align the numbers at the decimal marker.

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}

\usepackage[spanish]{babel}
\addto\captionsspanish{\renewcommand{\tablename}{Tabla}}

\usepackage[flushleft]{threeparttable}
\usepackage{booktabs}
\usepackage[detect-all,output-decimal-marker={,}]{siunitx}
\usepackage{tabularx}

\renewcommand\familydefault{\sfdefault}

\begin{document}

\begin{table}[th]
  \footnotesize
  \caption{Adultos mayores beneficiarios previsionales según grupo de edades y conformación del hogar, en \%}
  \label{tab:table32}
  \setlength\tabcolsep{3pt}
  \begin{threeparttable}
    \begin{tabular*}{\textwidth}{
      @{}
      l
      @{\extracolsep{\fill}}
      *{5}{
        S[table-format=2.1]
        S[table-format=2.1]
        S[table-format=-2.1]
      }
      @{}
      }
      \toprule
      & \multicolumn{3}{c}{65 a 69 años}
      & \multicolumn{3}{c}{70 a 74 años}
      & \multicolumn{3}{c}{75 a 79 años}
      & \multicolumn{3}{c}{80 y más años}
      & \multicolumn{3}{c}{Total} \\
      \cmidrule(lr){2-4} \cmidrule(lr){5-7}
      \cmidrule(lr){8-10} \cmidrule(lr){11-13}
      \cmidrule(lr){14-16}
      & {2003} & {2013} & {Var.}
      & {2003} & {2013} & {Var.}
      & {2003} & {2013} & {Var.}
      & {2003} & {2013} & {Var.}
      & {2003} & {2013} & {Var.}\\
      \midrule
      Hogar unipersonal
      & 20.8 & 16.3 & -4.5
      & 19.3 & 23.5 &  4.2
      & 30.2 & 29.0 & -1.2
      & 35.6 & 31.0 & -4.6
      & 26.8 & 24.7 & -2.1 \\
      Hogar bipersonal \\
      -- un solo beneficiario
      &  6.3 & 1.8 & -4.5
      & 17.0 & 1.3 & -15.7
      & 13.1 & 0.2 & -12.9
      & 10.0 & 0.7 & -9.3
      & 11.9 & 1.0 & -10.9 \\
      -- dos beneficiarios
      & 10.5 & 23.9 & 13.4
      & 20.2 & 26.4 & 6.2
      & 15.7 & 29.6 & 13.9
      & 13.4 & 26.0 & 12.6
      & 15.3 & 26.4 & 11.1 \\
      Hogar multipersonal
      & 62.4 & 58.0 & -4.4
      & 43.4 & 48.8 & 5.4
      & 41.0 & 41.2 & 0.1
      & 40.9 & 42.3 & 1.4
      & 46.0 & 48.0 & 1.9 \\
      \\
      \multicolumn{16}{@{}l@{}}{Adultos mayores en hogares unipersonales\textsuperscript{a}} \\
      Varones  & 28.3 & 28.9 & 0.6
      & 21.1 & 27.8 & 6.7
      & 23.1 & 24.1 & 1.0
      & 22.3 & 23.8 & 1.5
      & 23.3 & 25.7 & 2.5 \\
      Mujeres  & 71.7 & 71.1 & -0.6
      & 78.9 & 72.2 & -6.7
      & 76.9 & 75.9 & -1.0
      & 77.7 & 76.2 & -1.5
      & 76.7 & 74.3 & -2.5 \\
      \bottomrule
    \end{tabular*}

    \smallskip
    \footnotesize
    \begin{tablenotes}
    \item a: Como porcentaje del total de hogares unipersonales conformados por adultos mayores.
    \item Fuente: Elaboración propia en base a la EPH.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\end{document}

enter image description here

  • Oh! Thank you so much Henri! That's the layout I wanted! I didn't know about siunitx, so I'll try to learn about it. – eagu_999 Dec 23 '18 at 18:12

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.