1

I am a complete beginner on LaTex. I have 3 tables to show statistics about my 3 different sample. I want to combine them into a single table. First let me share the code I use to create 3 different table. The code is the same. I basically create 3 different table by copy-pasting 3 times this code (with different values of course).

\begin{table}
\centering
\begin{tabular}{@{}llccc@{}}
\toprule
          &                & \multicolumn{1}{l}{\textbf{Ambiguous}} & \multicolumn{1}{l}{\textbf{Unambiguous}} & \multicolumn{1}{l}{\textbf{Total}} \\ \midrule
          & \textbf{split-1} & 170266                                     & 197630                                       & 367896                                 \\
\textbf{} & \textbf{split-2}   & 21479                                     & 24645                                       & 46124                                 \\
          & \textbf{split-3}  & 21477                                     & 25166                                       & 46643                                
\end{tabular}
\caption{Statistics about first data}
\end{table}

It gives me the following figure:

enter image description here

As I said, I have 3 different table in total. I want to merge them and at the end I want to have a table similar to following:

enter image description here

Similar to my table aboe, I want to have 3 columns (Ambiguous,Unambiguous and Total) in my new table. Furthermore, I need to replace (death(all cause) row with train row of my table) and cancer death row with dev row of my table) and and one more row for each bold subsection. How can I do that ?

EDIT

I am able to draw a sketch to represent what I want roughly (but unfortunately no idea how to write latex code for that): enter image description here

0

In the following MWE I have removed the unnecessary first column, as you only need four columns for your table as well as all the superfluous \multicolumn commands.

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\begin{tabular}{@{}lccc@{}}
\toprule
     & \textbf{Ambiguous} & \textbf{Unambiguous}  & \textbf{Total} \\ 
\midrule
 \textbf{Dataset 1}\\
    Train  & 170266    & 197630    & 367896    \\
    Dev    & 21479     & 24645     & 46124     \\
    Test   & 21477     & 25166     & 46643     \\
  \midrule
     \textbf{Dataset 2}\\
    Train  &     &     &    \\
    Dev    &     &     &    \\
    Test   &     &     &    \\
  \midrule
   \textbf{Dataset 3}\\
    Train   &     &     &    \\
    Dev     &     &     &    \\
    Test    &     &     &    \\
  \bottomrule                          
\end{tabular}
\caption{Statistics about first data}
\end{table}

\end{document}

enter image description here

If you also want to slightly indent the entries 'train', 'dev' and 'test' you might also be interested in the following variant:

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\begin{tabular}{lccc@{}}
\toprule
          & \textbf{Ambiguous} & \textbf{Unambiguous}  & \textbf{Total} \\ \midrule
 \multicolumn{4}{@{}l}{\textbf{Dataset 1}}\\
    Train & 170266    & 197630    & 367896    \\
    Dev & 21479     & 24645     & 46124     \\
   Test  & 21477     & 25166     & 46643     \\
  \midrule
     \multicolumn{4}{@{}l}{\textbf{Dataset 2}}\\
    Train &     &     &    \\
    Dev &     &     &    \\
    Test &     &     &    \\
  \midrule
   \multicolumn{4}{@{}l}{\textbf{Dataset 3}}\\
    Train &     &     &    \\
    Dev &     &     &    \\
    Test &     &     &    \\
  \bottomrule                          
\end{tabular}
\caption{Statistics about first data}
\end{table}

\end{document}

enter image description here

2
  • Thanks @leandriss I used your second suggestion. It works but, the titles I actually use (MrMam 2012) is a bit longer than (Dataset 1). In that case, the word ambiguous starts before the MrMam 2012 ends, is there a way to move columns a little bit away ?
    – zwlayer
    May 20 '18 at 10:01
  • @zwlayer: If you use \multicolumn{1}{@{}l}{MrMam 2012} instead of \multicolumn{4}... the second to fourth column start farther to the right and the overlap disappears. However, I would suggest that you also take a look at the solutions by Zarko and egreg, especially regarding the usage of sitnitx's S columns for an improved formatting of numbers in table columns.
    – leandriis
    May 20 '18 at 12:57
2

You can use siunitx features for better typesetting the tables. I show two versions, one without the heavy boldface.

\documentclass{article}
\usepackage{siunitx,booktabs}

\begin{document}

\begin{table}[htp]
\centering

\begin{tabular}{
  l
  S[table-format=6.0]
  S[table-format=6.0]
  S[table-format=6.0]
  @{}
}
\toprule
 & {\textbf{Ambiguous}} & {\textbf{Unambiguous}} & {\textbf{Total}} \\
\midrule
\multicolumn{4}{@{}l}{\textbf{Dataset-1}} \\
\textbf{split-1} & 170266 & 197630 & 367896 \\
\textbf{split-2} &  21479 &  24645 &  46124 \\
\textbf{split-3} &  21477 &  25166 &  46643 \\
\midrule
\multicolumn{4}{@{}l}{\textbf{Dataset-2}} \\
\textbf{split-1} & 170266 & 197630 & 367896 \\
\textbf{split-2} &  21479 &  24645 &  46124 \\
\textbf{split-3} &  21477 &  25166 &  46643 \\
\midrule
\multicolumn{4}{@{}l}{\textbf{Dataset-3}} \\
\textbf{split-1} & 170266 & 197630 & 367896 \\
\textbf{split-2} &  21479 &  24645 &  46124 \\
\textbf{split-3} &  21477 &  25166 &  46643 \\
\bottomrule
\end{tabular}

\caption{Statistics about first data}

\end{table}

\begin{table}[htp]
\centering

\begin{tabular}{
  l
  S[table-format=6.0]
  S[table-format=6.0]
  S[table-format=6.0]
  @{}
}
\toprule
 & {Ambiguous} & {Unambiguous} & {Total} \\
\midrule
\multicolumn{4}{@{}l}{\textit{Dataset-1}} \\
split-1 & 170266 & 197630 & 367896 \\
split-2 &  21479 &  24645 &  46124 \\
split-3 &  21477 &  25166 &  46643 \\
\midrule
\multicolumn{4}{@{}l}{\textit{Dataset-2}} \\
split-1 & 170266 & 197630 & 367896 \\
split-2 &  21479 &  24645 &  46124 \\
split-3 &  21477 &  25166 &  46643 \\
\midrule
\multicolumn{4}{@{}l}{\textit{Dataset-3}} \\
split-1 & 170266 & 197630 & 367896 \\
split-2 &  21479 &  24645 &  46124 \\
split-3 &  21477 &  25166 &  46643 \\
\bottomrule
\end{tabular}

\caption{Statistics about first data}

\end{table}

\end{document}

enter image description here

2

like this?

enter image description here

if you need more groups (three), you just add as is shown on image and provided in mwe:

\documentclass{article}
\usepackage[skip=1ex]{caption}  % new
\usepackage{siunitx}            % new
\usepackage{booktabs, 
            makecell}           % new
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{}
\newcommand\mcbf[1]{\multicolumn{2}{@{} l}{\textbf{#1}}}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%


\begin{document}
    \begin{table}
\caption{Statistics about first data}
\label{tab:stat-sumary}
\centering
\begin{tabular}{@{} l
                    l
               *{3}{S[group-four-digits,
                      table-format=6]}
                @{}}
    \toprule
    &       &   {\thead{Ambiguous}} &   {\thead{Unambiguous}}   &   {\thead{Total}}  \\
    \midrule
\mcbf{Dataset 1}                                                &   &   &           \\
    & Train &   170266              &   197630                  &   367896          \\
    & Dev   &    12312              &       44                  &    12345          \\
    & Test  &   123123              &      888                  &    98765          \\
    \midrule
\mcbf{Dataset 2}                                                &   &   &           \\
    & Train &   170266              &   197630                  &   367896          \\
    & Dev   &    12312              &       44                  &    12345          \\
    & Test  &   123123              &      888                  &    98765          \\
    \bottomrule
\end{tabular}
\end{table}
    \end{document}

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.