2

I have a table which consists of two parts (tabulars). It looks similar to the excerpt attached below.

Now what I would like to do is format the second part (tabular) of the table nicely. That means:

  • The second part of the table should also start on the very left margin, exactly where the first part of the table starts.
  • The \hline at the end should go over the same width as hlines from the first part of the table, so it does not look too short.
  • I might also add a third test result to the bottom, of simular structure as the first two. Thus, the width should probably be adjustable somehow.

I am open to any solution, but I am preferably looking for a solution in booktabs and the packages I am using in this example.

Thanks for any hints!

\documentclass[11pt,notitlepage]{article}
\usepackage[a4paper]{geometry}
\geometry{left=3cm,right=3cm,top=3cm,bottom=3cm,foot=1cm}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern, textcomp}
\usepackage{csquotes}
\usepackage{ragged2e}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\usepackage{booktabs, makecell, longtable, tabularx, threeparttable}
\usepackage[font=small]{caption}
\usepackage{lscape}
\usepackage{rotating}
\usepackage{pdflscape} 
\usepackage{caption}
\usepackage{booktabs}
\usepackage{pdfpages} 
\usepackage{enumitem} 
\usepackage{titling}
\usepackage[export]{adjustbox}
\usepackage{mathptmx}

\begin{document}

\begin{landscape}
\begin{table}
 \centering
 \caption{Test results}
  \begin{tabular}{lccccccccccccc}
  \hline
  Probability d1 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d2 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d3 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d4 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d5 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d6 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d7 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d8 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d9 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d10 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d11 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d12 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d13 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d14 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d15 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d16 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  \hline
  \end{tabular}%


    \begin{tabular}{lrlrlrl}
    Object 1 x Object 2 &   & \multicolumn{1}{r}{0.34345} & & Object 3 x Object 4 &   & \multicolumn{1}{r}{0.8794} \\
    Test performance & & \multicolumn{1}{r}{0.33434} & & Test performance & & \multicolumn{1}{r}{0.1231} \\
    Items involved & & Item A, Item B & & Items involved & & Item A, Item B \\
    Score achieved & & \multicolumn{1}{r}{0.9999} & & Score achieved & & \multicolumn{1}{r}{0.6784} \\
    Test result positive? & & yes  &  & Test result positive? & & yes \\
    \hline
    \end{tabular}%



    \end{table}%
    \end{landscape}

    \end{document}
2

To achieve the desired output, you can nest the second tabular environment into a multicolumn in the first tabular. Since you have tgged the question with booktabs and already load the package, I have replaced \hline with the rules from said package:

enter image description here

If you want to add a third set of test results to the second tabular, you might need to do some adjustments. In the second example, I have removed the empty columns between the frst and second, as well as between the thrid and fourth column of the second tabular to save some horizontal space. Otherwise the second tabular would be wider than the first causing the last column of the first tabular to be widened:

enter image description here

\documentclass[11pt,notitlepage]{article}
\usepackage[a4paper]{geometry}
\geometry{left=3cm,right=3cm,top=3cm,bottom=3cm,foot=1cm}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern, textcomp}
\usepackage{csquotes}
\usepackage{ragged2e}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\usepackage{booktabs, makecell, longtable, tabularx, threeparttable}
\usepackage[font=small]{caption}
\usepackage{lscape}
\usepackage{rotating}
\usepackage{pdflscape} 
\usepackage{caption}
\usepackage{booktabs}
\usepackage{pdfpages} 
\usepackage{enumitem} 
\usepackage{titling}
\usepackage[export]{adjustbox}
\usepackage{mathptmx}

\begin{document}

\begin{landscape}
\begin{table}
 \centering
 \caption{Test results}
  \begin{tabular}{lccccccccccccc}
%  \hline
\toprule
  Probability d1 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d2 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d3 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d4 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d5 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d6 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d7 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d8 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d9 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d10 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d11 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d12 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d13 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d14 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d15 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d16 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
 % \hline
 \midrule
 \multicolumn{14}{@{}l@{}}{    \begin{tabular}{lrlrlrl}
    Object 1 x Object 2 &   & \multicolumn{1}{r}{0.34345} & & Object 3 x Object 4 &   & \multicolumn{1}{r}{0.8794} \\
    Test performance & & \multicolumn{1}{r}{0.33434} & & Test performance & & \multicolumn{1}{r}{0.1231} \\
    Items involved & & Item A, Item B & & Items involved & & Item A, Item B \\
    Score achieved & & \multicolumn{1}{r}{0.9999} & & Score achieved & & \multicolumn{1}{r}{0.6784} \\
    Test result positive? & & yes  &  & Test result positive? & & yes \\
    %\hline
    \end{tabular}}\\
      \bottomrule
  \end{tabular}%

    \end{table}%
    \end{landscape}



\begin{landscape}
\begin{table}
 \centering
 \caption{Test results}
  \begin{tabular}{lccccccccccccc}
%  \hline
\toprule
  Probability d1 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d2 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d3 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d4 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d5 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d6 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d7 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d8 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d9 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d10 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d11 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d12 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d13 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d14 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
  Probability d15 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 & 0.123 \\
  Probability d16 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 & 0.421 \\
 % \hline
 \midrule
 \multicolumn{14}{@{}l@{}}{    \begin{tabular}{llrllrll}
    Object 1 x Object 2 &    \multicolumn{1}{r}{0.34345} & & Object 3 x Object 4 &    \multicolumn{1}{r}{0.8794} & & Object 3 x Object 4 &    \multicolumn{1}{r}{0.8794} \\
    Test performance &  \multicolumn{1}{r}{0.33434} & & Test performance  & \multicolumn{1}{r}{0.1231}  & & Test performance  & \multicolumn{1}{r}{0.1231} \\
    Items involved &  Item A, Item B & & Items involved &  Item A, Item B  & & Items involved &  Item A, Item B \\
    Score achieved &  \multicolumn{1}{r}{0.9999} & & Score achieved &  \multicolumn{1}{r}{0.6784}  & & Score achieved &  \multicolumn{1}{r}{0.6784} \\
    Test result positive? &  yes  &  & Test result positive? &  yes   &  & Test result positive? &  yes \\
    %\hline
    \end{tabular}}\\
      \bottomrule
  \end{tabular}%

    \end{table}%
    \end{landscape}

    \end{document}
| improve this answer | |
  • thanks a lot very helpful and looks excellent. – ghx Sep 18 '19 at 10:01
  • short follow-up: What if the first table is the smaller one, and the second one the larger? (opposite as in the above example) In this case, the first tabular (of the smaller table) seems to be stretched to the full width, but columns are not evenly distributed anymore? – ghx Sep 27 '19 at 17:11
  • @ghx: That's unfortunately true. Depending on the table there might be different ways on how to achieve a more pleasing look. If you have a specific example table in mind, please post a follow up question to this one. – leandriis Sep 27 '19 at 17:18

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.