1

I am trying to build a very simple multi-index table, yet I cannot get the columns of the lower index aligned properly. With the following code:

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{booktabs}
\begin{document}
    \begin{table}[!ht]
        \centering
        \caption{
            {\bf Table caption Nulla mi mi, venenatis sed ipsum varius, volutpat euismod diam.}}
        \begin{tabular}{@{}lcccc@{}}
            \toprule
            & \multicolumn{4}{c}{\textbf{Peptide concentration {[}mg/ml{]}}} \\ \midrule
            & \textbf{0.29}  & \textbf{0.57}  & \textbf{1.15} & \textbf{2.3} \\
            \textbf{Difference (VL/NEHC)} & 1.58           & 1.48           & 1.82          & 1.03         \\ \bottomrule
        \end{tabular}
        %\begin{flushleft} Table notes Phasellus venenatis, tortor nec vestibulum mattis, massa tortor interdum felis, nec pellentesque metus tortor nec nisl. Ut ornare mauris tellus, vel dapibus arcu suscipit sed.
        %\end{flushleft}
        \label{tab:caption}
    \end{table}
\end{document}

We can see that my table looks acceptable, but we can see that the columns below "Peptide concentration [mg/ml]" are not evenly distributed/ aligned (I was expecting them to be evenly distributed under "Peptide concentration [mg/ml]".

How can I distribute these four columns under "Peptide concentration [mg/ml]" equally spaced?

Thanks

1

You can use makecell to split the table head in two lines, siunitx for numbers alignment, and threeparttable for table notes. I added caption to have a decent spacing between caption and table:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{booktabs, threeparttable, makecell, caption}
\usepackage{siunitx}
\usepackage{etoolbox}
\robustify\bfseries
\author{Bruno Hinckel}

\begin{document}

\begin{threeparttable}[!ht]
    \centering
\sisetup{table-format=1.2, table-number-alignment=center, detect-weight, ,detect-inline-weight=math}
\captionsetup{font=bf}
        \caption{
            {Table caption Nulla mi mi, venenatis sed ipsum varius, volutpat euismod diam.}}
        \label{tab:caption}
        \begin{tabular}{@{}l*{4}{S}@{}}
            \toprule
            & \multicolumn{4}{>{\bfseries}c}{\makecell{Peptide concentration \\[-0.5ex] [mg/ml]}} \\
            \midrule
            & \bfseries 0.29 & \bfseries 0.57 & \bfseries 1.15 & \bfseries 2.3 \\
            \textbf{Difference (VL/NEHC)} & 1.58 & 1.48 & 1.82 & 1.03 \\ \bottomrule
        \end{tabular}
\footnotesize\smallskip
        \begin{tablenotes}[flushleft] \item[]\emph{Table notes}. Phasellus venenatis, tortor nec vestibulum mattis, massa tortor interdum felis, nec pellentesque metus tortor nec nisl. Ut ornare mauris tellus, vel dapibus arcu suscipit sed.
        \end{tablenotes}
\end{threeparttable}

\end{document} 

enter image description here

0

What happens is that the rows under your header row are not aware of the fact that the top row is bigger than the other rows and extends its space. Therefore only the last of the four columns is actually extended. So the centering of the values inside their columns works. You can see it when enabling vertical rulers between columns:

table with vertical rulers

Your number columns will never be aware of the header column so one option would be to replace the values with an entire new table that defines its own column sizes or setting the column sizes manually.

Alternatively you could also just make your table left-bound like this:

left-bound table

Which looks splendid to me, but I guess it's a matter of taste. For this result change the following line in your code:

\begin{tabular}{lllll}

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.