0

How can I top align these two tables, and possibly prevent them from overlapping each other?

\documentclass[12pt]{article}   
\usepackage{booktabs}  
\usepackage{siunitx}      
\usepackage{subcaption}

\begin{document}
    \begin{table}[h]
    \centering
    \renewcommand{\arraystretch}{1.25}%
    \begin{subtable}[t]{0.4\textwidth}
        \begin{tabular}{cc}
            \toprule
            Numero d'onda ($\unit{cm^{-1}}$) & Classificazione \\ \midrule
            3204 & weak \\
            3183 & weak \\
            3167 & weak \\ \midrule
            3139 & weak \\ \midrule
            3087 & weak \\
            3072 & weak \\ \midrule
            1856 & strong \\ \midrule
            1511 & weak \\
            1493 & weak \\ \midrule
            1415 & strong \\ \midrule
            1257 & strong \\ \midrule
            1128 & weak \\ \midrule
            938 & weak \\ \midrule
            525 & medium \\ \midrule
            378 & weak \\
            \bottomrule
        \end{tabular}
    \end{subtable}
        \quad
        \begin{tabular}{cc}
            \toprule
            Numero d'onda ($\unit{cm^{-1}}$) & Classificazione \\ \midrule
            3204 & medium \\
            3183 & medium \\
            3167 & medium \\
            3139 & medium \\ \midrule
            3097 & strong \\
            3072 & strong \\ \midrule
            1856 & weak \\ \midrule
            1511 & medium \\ 
            1510 & medium \\
            1493 & weak \\ \midrule
            1411 & weak \\
            1089 & weak \\ \midrule
            938 & weak \\ \midrule
            891 & weak \\ \midrule
            799 & medium \\
            \bottomrule
        \end{tabular}
    \end{table}
\end{document}

1 Answer 1

2

The contents of table cells does not break by default and in your case results in the tabulars being too wide. You can't restrict the width of a tabular using a subtable in this way.

A simple solution that reduces the width of both tabulars by inserting a line break in the header of the left column (without even using subtables) could be:

\documentclass[12pt]{article}   
\usepackage{booktabs}  
\usepackage{siunitx}      

\begin{document}
    \begin{table}[h]
    \centering
    \renewcommand{\arraystretch}{1.25}%
        \begin{tabular}[t]{cc}
            \toprule
            \shortstack{Numero d'onda \\ ($\unit{cm^{-1}}$)} & Classificazione \\ \midrule
            3204 & weak \\
            3183 & weak \\
            3167 & weak \\ \midrule
            3139 & weak \\ \midrule
            3087 & weak \\
            3072 & weak \\ \midrule
            1856 & strong \\ \midrule
            1511 & weak \\
            1493 & weak \\ \midrule
            1415 & strong \\ \midrule
            1257 & strong \\ \midrule
            1128 & weak \\ \midrule
            938 & weak \\ \midrule
            525 & medium \\ \midrule
            378 & weak \\
            \bottomrule
        \end{tabular}
        \quad
        \begin{tabular}[t]{cc}
            \toprule
            \shortstack{Numero d'onda \\ ($\unit{cm^{-1}}$)} & Classificazione \\ \midrule
            3204 & medium \\
            3183 & medium \\
            3167 & medium \\
            3139 & medium \\ \midrule
            3097 & strong \\
            3072 & strong \\ \midrule
            1856 & weak \\ \midrule
            1511 & medium \\ 
            1510 & medium \\
            1493 & weak \\ \midrule
            1411 & weak \\
            1089 & weak \\ \midrule
            938 & weak \\ \midrule
            891 & weak \\ \midrule
            799 & medium \\
            \bottomrule
        \end{tabular}
    \end{table}
\end{document}

enter image description here

Another solution could be to use tabularx:

\documentclass[12pt]{article}   
\usepackage{tabularx}      
\usepackage{booktabs}  
\usepackage{siunitx}      

\begin{document}
    \begin{table}[h]
    \centering
    \renewcommand{\arraystretch}{1.25}%
        \begin{tabularx}{0.475\textwidth}[t]{ *{2}{>{\centering\arraybackslash}X} }
            \toprule
            Numero d'onda ($\unit{cm^{-1}}$) & Classificazione \\ \midrule
            3204 & weak \\
            3183 & weak \\
            3167 & weak \\ \midrule
            3139 & weak \\ \midrule
            3087 & weak \\
            3072 & weak \\ \midrule
            1856 & strong \\ \midrule
            1511 & weak \\
            1493 & weak \\ \midrule
            1415 & strong \\ \midrule
            1257 & strong \\ \midrule
            1128 & weak \\ \midrule
            938 & weak \\ \midrule
            525 & medium \\ \midrule
            378 & weak \\
            \bottomrule
        \end{tabularx}
        \quad
        \begin{tabularx}{0.475\textwidth}[t]{ *{2}{>{\centering\arraybackslash}X} }
            \toprule
            Numero d'onda ($\unit{cm^{-1}}$) & Classificazione \\ \midrule
            3204 & medium \\
            3183 & medium \\
            3167 & medium \\
            3139 & medium \\ \midrule
            3097 & strong \\
            3072 & strong \\ \midrule
            1856 & weak \\ \midrule
            1511 & medium \\ 
            1510 & medium \\
            1493 & weak \\ \midrule
            1411 & weak \\
            1089 & weak \\ \midrule
            938 & weak \\ \midrule
            891 & weak \\ \midrule
            799 & medium \\
            \bottomrule
        \end{tabularx}
    \end{table}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .