[Tex/LaTex] Alignment in table

horizontal alignmenttables

I'm creating a table but I'm not getting the correct alignment in the last row of the table. It's a multirow and muticolumn example. Of course, I'm putting some fictitious information and data in the table 🙂 but my original table has the same format. I'm putting a minimal code below. There are two problems:

  1. I can't get the numbers 12 and 1000 in the last column aligned in the center position as the other numbers are. Now I have simple small numbers as 12 and 1000 but the alignment becomes worse if I have bigger numbers and with decimals.

  2. A second problem is setting the 10 and 3 in the "sex ratio between second and first value" rows to be aligned in the middle between "male" and "female".

    \documentclass[10pt]{article}
    \usepackage[latin1]{inputenx}
    \usepackage[T1]{fontenc}
    \usepackage{amssymb}
    \usepackage{amsmath}
    \usepackage{booktabs}
    \usepackage[below]{placeins}
    \usepackage{threeparttable}
    \usepackage{multirow}
    
    \begin{document}
    \begin{table}[htbp]
    \begin{center}
    \begin{threeparttable}
    \caption{\label{tab:freqcompa} Testing for table}
    
    \begin{tabular}{@{}lcccc@{}}
    \toprule
    \multicolumn{1}{c}{\multirow{2}{2cm}{Case\tnote{2}}} & \multicolumn{4}{c}{Number 
    of dogs} \\
    \cmidrule(r){2-5}
    \multicolumn{1}{c}{} & \multicolumn{2}{c}{Dogs of type 1} & \multicolumn{2}{c}{
    Very very bad Dogs of type 2\tnote{1}} \\
    \midrule
    \multicolumn{1}{c}{} & \multicolumn{1}{c}{male} & \multicolumn{1}{c}{female}
    & \multicolumn{1}{c}{male} & \multicolumn{1}{c}{female}\\
    $\omega_a= 100$  & $1$ & $2$ & $4$ & $12$ \\[2mm]
    \cmidrule(r){1-1}
    Sex ratio \\[-1.5mm]
    between second \\[-1.5mm]
    and first value & \multicolumn{2}{c}{$2$}  & \multicolumn{2}{c}{$3$} \\[2.3mm]
    \midrule
    \multicolumn{1}{c}{} & \multicolumn{1}{c}{male} & \multicolumn{1}{c}{female}
    & \multicolumn{1}{c}{male} & \multicolumn{1}{c}{female}\\
    $\omega_b= 200$ & $1$ & $60$ & $100$ & $1000$ \\[2mm]
    \cmidrule(r){1-1}
    Sex ratio \\[-1.5mm]
    between second \\[-1.5mm]
    and first value & \multicolumn{2}{c}{$60$}  & \multicolumn{2}{c}{$10$} \\[2.3mm]
    
    \bottomrule
    \end{tabular}
    \begin{tablenotes}
    \item[1]\textit{considering all stray dogs.}
    \item[2]\textit{considering two possible cases}
    \end{tablenotes}
    
    \end{threeparttable}
    \end{center}
    \end{table}
    \end{document} 
    

Any help will be most appreciated…

Best Answer

To explain the alignment behavior: by this line

\begin{tabular}{@{}lcccc@{}}

you format the last column by c@{}, removing the small space which would follow. But here

... & \multicolumn{1}{c}{female}\\

you would get this default space. That's the reason why the numbers and the word 'female' aren't aligned correctly. Change to

... & \multicolumn{1}{c@{}}{female}\\

and you will notice, that 'female', 12 and 1000 will become horizontally centered.

Related Question