2

I have to make three tables and I am using the code below.

\begin{table}[ht]
\caption{Performance of each band on recognizing classes 1 and 2} \label{tab1}
\begin{tabularx}{\textwidth}{|*{4}{L|}}
\hline
    \multirow{2}{*}{Band} &
      \multicolumn{2}{c}{CCS} & \\
      & {Class 1} & {Class 2} \\
      \midrule
    Alpha & 61 & 55 & \\
\hline
    Beta & 70 & 59 &\\
\hline
    Theta & 55 & 65 &\\
\hline
\end{tabularx}
\end{table}

\begin{table}[ht] \caption{Performance of each band on recognizing classes 1 and 3} \label{tab1} \begin{tabularx}{\textwidth}{|{4}{L|}} \hline \multirow{2}{}{Band} & \multicolumn{2}{c}{CCS} & \ & {Class 2} & {Class 3} \ \midrule Alpha & 49 & 56&
\hline Beta & 73 & 36&\ \hline Theta & 52 & 57& \ \hline \end{tabularx} \end{table}

\begin{table}[ht] \caption{Performance of each band on recognizing classes 2 and 3} \label{tab1} \begin{tabularx}{\textwidth}{|{4}{L|}} \hline \multirow{2}{}{Band} & \multicolumn{2}{c}{CCS} & \ & {Class 2} & {Class 3} \ \midrule Alpha & 58 & 57 &\ \hline Beta & 62 & 52 & \ \hline Theta & 66 & 58 & \ \hline \end{tabularx} \end{table}

And as expected, I got the tables as shown in the image below. enter image description here

But this is taking too much space. I want to put all the three tables in a single row side by side. How can I do that?

  • 1
    Dear Muhammed, shall all three tables still have a separate caption? If so, then take a look into minipage. – Gunter Jun 13 '21 at 11:25
  • 2
    tabular go side by side by default, just put them in the same table but why are you using tabularx here and forcing the tables to be unnaturally wide, and why specify 4 columns when they only have 3? Please always provide code in a form that reproduces the image shown. You have posted a fragment with undefined commands like \multirow and undefined column type L, your code apperas to show tables with a vertical rule from | but the image shown has no rules. – David Carlisle Jun 13 '21 at 11:38
  • All three approaches shown here https://tex.stackexchange.com/a/597566/134144 should also be applicable to your tables. – leandriis Jun 13 '21 at 12:01
  • Entirely unrelated to the question, but did you notice that your table number increases in steps of 2 instead of in steps of 1? You may want to fix that. – leandriis Jun 13 '21 at 12:02
  • And how do you define the L column type, if you don't mind? – Bernard Jun 13 '21 at 12:11
  • You shouldn't use tabularx without an X type column, and the default (array package) L column is not based on X (not to mention that the tabulars are not \textwidth wide). – John Kormylo Jun 13 '21 at 16:36

1 Answers1

3

Like this:

enter image description here

\documentclass{article}
\usepackage{booktabs, multirow, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\NewExpandableDocumentCommand\mcc{O{1}m}{\multicolumn{#1}{c}{#2}}
\usepackage{setspace}
\usepackage[skip=1ex, 
            font={footnotesize,sf,stretch=0.88},
            labelfont=bf
            ]{caption}

\begin{document} \begin{table}[ht] \small \begin{tabularx}{\textwidth}{@{} {3}{C} @{}} \caption{Performance of each band on recognizing classes 1 and 2} \label{tab1} \begin{tabular}{@{} lcc @{}} \toprule \multirow{2.3}{}{Band} & \mcc[2]{CCS} \ \cmidrule(l){2-3} & Class 1 & Class 2 \ \midrule Alpha & 61 & 55 \ Beta & 70 & 59 \ Theta & 55 & 65 \ \bottomrule \end{tabular} & \caption{Performance of each band on recognizing classes 2 and 3} \label{tab1} \begin{tabular}{@{} lcc @{}} \toprule \multirow{2.3}{}{Band} & \mcc[2]{CCS} \ \cmidrule(l){2-3} & Class 1 & Class 2 \ \midrule Alpha & 61 & 55 \ Beta & 70 & 59 \ Theta & 55 & 65 \ \bottomrule \end{tabular} & \caption{Performance of each band on recognizing classes 2 and 3} \label{tab1} \begin{tabular}{@{} lcc @{}} \toprule \multirow{2.3}{}{Band} & \mcc[2]{CCS} \ \cmidrule(l){2-3} & Class 1 & Class 2 \ \midrule Alpha & 61 & 55 \ Beta & 70 & 59 \ Theta & 55 & 65 \ \bottomrule \end{tabular} \end{tabularx} \end{table} \end{document}

Zarko
  • 296,517