# Table using \multicolum and \multirow

I'm working on Latex to generate the following table,

I want columns that have numbers to be right aligned and similar sized.

Here is a minimal code example to start the discussion:

\documentclass{book}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{threeparttable}
\usepackage[margin=1in]{geometry}
\begin{document}

\begin{table}[h]
\small
\centering
\caption{Descomposici\'on est\'atica del \'{\i}ndice de Theil del ingreso per c\'apita familiar}

\begin{threeparttable}
\resizebox{\textwidth}{!}{%
\begin{tabular}{@{}lrrrrrrrrrrrrrrr@{}}
\toprule
\cline{3-6}\cline{7-10}
&  &  &  & \multicolumn{2}{l}{Contribuci\'on} & & & \multicolumn{2}{l}{Contribuci\'on} & \multicolumn{2}{c}{Efecto Intragrupal} & \multicolumn{2}{c}{Efecto Intergrupal} & \\
&  & Theil & Pob \% & Abs & Rel \% & Theil & Pob \% & Abs & Rel \% & Abs & Rel \% & Abs & Rel \% \\ \hline
\midrule
2003 & 0,448 & 0,458 & 79,5 & 0,349 & 78,1 & 0,403 & 20,5 & 0,096 & 21,3        & 0,445 & 99,4 & 0,003 & 0,7 \\
2004 & 0,421 & 0,445 & 79,5 & 0,340 & 80,8 & 0,332 & 20,5 & 0,078 & 18,6 & 0,418 & 99,4 & 0,003 & 0,7 \\ \hline
\bottomrule
\end{tabular}}

\begin{tablenotes}
\footnotesize
\item Fuente: Elaboraci\'on propia en base a la EPH.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}


From this code, I get this table:

As you can see, I cannot set a similar size for the columns that have numbers. I went over the threads that discuss \multicolumn and \multirow, but I still don't understand how to make these columns evenly distributed. What can I do to resolve this?

Thank you,

• Off topic: Currently with UTF8 encoding it is not needed write "Descomposici\'on" or "A\~no". Just write "Año" and compile it with xelatex or lualatex, or with pdflatex but in this case add \usepackage[ut8]{inputenc} in the preamble.
– Fran
Nov 16 '17 at 2:01
• Thank you @Fran. I'll try to implement your suggestion. I'm using \usepackage[utf8]{inputenc} already, and compiling with TeXShop, but the Spanish characters don't appear. Nov 16 '17 at 2:43
• Try only \documentclass{article} \usepackage[utf8]{inputenc} \begin{document} Año camión \end{document} . It must work with pdflatex.
– Fran
Nov 16 '17 at 17:24
• I just found out the way to use the special Spanish characters following this explanation: tex.stackexchange.com/a/271977/148321 Mar 11 '18 at 1:30

Don't use \resizebox -- as you've found out, the size of the glyphs becomes so small as to make them virtually illegible. Instead, use tabularx environment and permit linebreaks in the two large header cells.

\documentclass{book}
\usepackage{booktabs,ragged2e}
\usepackage[spanish]{babel}
\usepackage[flushleft]{threeparttable}
\usepackage[margin=1in]{geometry} % choose page size parameters suitably

\usepackage{tabularx}
\newcolumntype{C}{>{\Centering\arraybackslash}X} % centered version of 'X' col.

\begin{document}

\begin{table}[h]
%\small
\setlength\tabcolsep{2pt}
\begin{threeparttable}
\caption{Descomposici\'on est\'atica del \'indice de Theil del ingreso per c\'apita familiar}

\begin{tabularx}{\textwidth}{@{} l *{13}{C} @{}}
\toprule
A\~no & Theil global
\cmidrule(lr){3-6} \cmidrule(lr){7-10}
& & & & \multicolumn{2}{c}{Contribuci\'on}
& & & \multicolumn{2}{c}{Contribuci\'on}
& \multicolumn{2}{c}{Intragrupal}
& \multicolumn{2}{c@{}}{Intergrupal} \\
\cmidrule(lr){5-6} \cmidrule(lr){9-10} \cmidrule(lr){11-12} \cmidrule(l){13-14}

&  & Theil & Pob\,\% & Abs & Rel\,\%
& Theil & Pob\,\% & Abs & Rel\,\%
& Abs   & Rel\,\% & Abs & Rel\,\% \\
\midrule
2003 & 0,448 & 0,458 & 79,5 & 0,349 & 78,1
& 0,403 & 20,5 & 0,096 & 21,3
& 0,445 & 99,4 & 0,003 & 0,7 \\
2004 & 0,421 & 0,445 & 79,5 & 0,340 & 80,8
& 0,332 & 20,5 & 0,078 & 18,6
& 0,418 & 99,4 & 0,003 & 0,7 \\
\bottomrule
\end{tabularx}
\smallskip
\small
\begin{tablenotes}
\item{}Fuente: Elaboraci\'on propia en base a la EPH.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

• Thanks Mico! Your suggestion makes the table exactly as I need it. That's wonderful! Nov 16 '17 at 2:23
• @eagu_999 - I was going mostly by the screenshot of what you said you wanted to replicate. You're obviously free to make changes.
– Mico
Nov 16 '17 at 2:28
• I would upgrade the table in two ways. Firstly, I would align the text of the first two colums in the botton of the cell. This is something that I partially achieved by placing "Año" and "Theil" at the begining of the third row of \multicolumn statements, and "global" just before "Theil" in the row rigth after the second \cmidrule. Secondly, I would use the title "Efecto intra-grupal" and "Efecto inter-grupal" instead of only the "intra-grupal" and "inter-grupal", but I couldn't get a good solution for this. Nov 16 '17 at 2:35
• Sorry, I made some mistakes when answering to your post because I'm new to this forum. But, I certainly try to practice to do better next time. Nov 16 '17 at 2:37