1

How can I easily place these two tables that I have beside each other?

\begin{table}[H]
    \small
    \begin{tabu} to \textwidth {  X[l] | X[c]  X[c]  X[c]  X[c]  X[c] }
%        \hline
        & \multicolumn{5}{c}{Precision} \\
%        \cline{5-6}
        & 0 & 1 & 2 & 3 & 4\\
        \hline
        A & 0.143 & 0.143 & & & \\
        B & 1.518 & 1.518 \\
        C & 0.018 & 0.142 \\
        D & 0.029 & 0.180 \\
        \hline
        \# tr samples & 53k, 187k & 53k, 187k & 53k, 187k \\
        \# te samples & 8k, 26k & \\
%        \hline
        \end{tabu}
    \medskip
    \caption{}
    \label{tab:runtime}     
\end{table}

\begin{table}[H]
    \small
    \begin{tabu} to \textwidth {  X[l] | X[c]  X[c]  X[c]  X[c]  X[c] }
%        \hline
        & \multicolumn{5}{c}{Precision} \\
%        \cline{5-6}
        & 0 & 1 & 2 & 3 & 4\\
        \hline
        A & 0.143 & 0.143 & & & \\
        B & 1.518 & 1.518 \\
        C & 0.018 & 0.142 \\
        D & 0.029 & 0.180 \\
        E & 0.029 & 0.180 \\
        F & 0.029 & 0.180 \\
%        \hline
        \end{tabu}
    \medskip
    \caption{}
    \label{tab:runtime}     
\end{table}

EDIT: I tried putting them under the same \begin{table} and \end{table} but they are still not side by side.

\begin{table}[H]
    \small
    \begin{tabu} to 0.5\textwidth {  X[l] | X[c]  X[c]  X[c]  X[c]  X[c] }
%        \hline
        & \multicolumn{5}{c}{Precision with label shifted by t seconds} \\
%        \cline{5-6}
        & 0 & 1 & 2 & 3 & 4\\
        \hline
        A & 0.143 & 0.143 & & & \\
        B & 1.518 & 1.518 \\
        C & 0.018 & 0.142 \\
        D & 0.029 & 0.180 \\
        \hline
        \# tr samples & 53k, 187k & 53k, 187k & 53k, 187k \\
        \# te samples & 8k, 26k & \\
%        \hline
        \end{tabu}
    \medskip
    \caption{Models trained and tested on the complete sequence as described in figure 3a.}
    \label{tab:runtime}  

    \small
    \begin{tabu} to 0.5\textwidth {  X[l] | X[c]  X[c]  X[c]  X[c]  X[c] }
%        \hline
        & \multicolumn{5}{c}{Precision with label shifted by t seconds} \\
%        \cline{5-6}
        & 0 & 1 & 2 & 3 & 4\\
        \hline
        A & 0.143 & 0.143 & & & \\
        B & 1.518 & 1.518 \\
        C & 0.018 & 0.142 \\
        D & 0.029 & 0.180 \\
        E & 0.029 & 0.180 \\
        F & 0.029 & 0.180 \\
%        \hline
        \end{tabu}
    \medskip
    \caption{Models trained on the complete sequence (fig 3a) and tested on the truncated sequence (fig 3b).}
    \label{tab:runtime} 

\end{table}

I have removed all white spaces but it is still not working

\begin{table}[H]
    \small
    \begin{tabu} to \textwidth {  X[l] | X[c]  X[c]  X[c]  X[c]  X[c] }
        & \multicolumn{5}{c}{Precision} \\
        & 0 & 1 & 2 & 3 & 4\\
        \hline
        A & 0.143 & 0.143 & & & \\
        B & 1.518 & 1.518 \\
        C & 0.018 & 0.142 \\
        D & 0.029 & 0.180 \\
        \hline
        \# tr samples & 53k, 187k & 53k, 187k & 53k, 187k \\
        \# te samples & 8k, 26k & \\
    \end{tabu}
    \caption{}
    \label{tab:runtime}  
    \small\begin{tabu} to \textwidth {  X[l] | X[c]  X[c]  X[c]  X[c]  X[c] }
        & \multicolumn{5}{c}{Precision with label shifted by t seconds} \\
        & 0 & 1 & 2 & 3 & 4\\
        \hline
        A & 0.143 & 0.143 & & & \\
        B & 1.518 & 1.518 \\
        C & 0.018 & 0.142 \\
        D & 0.029 & 0.180 \\
        E & 0.029 & 0.180 \\
        F & 0.029 & 0.180 \\
        \end{tabu}
    \caption{}
    \label{tab:runtime} 
\end{table}
  • Put them inside the same \begin{table}...\end{table}. – Phelype Oleinik May 29 at 13:37
  • @PhelypeOleinik I tried putting them under the same \begin{table} and \end{table} but they are still not side by side. – Kong May 29 at 13:41
  • 1
    In TeX an empty line means a paragraph break, so you should remove that as well. However I don't know if you can have side-by-side tables with tabu... – Phelype Oleinik May 29 at 13:44
  • i removed the empty line and it is still not working. so how else can i make them side by side? – Kong May 29 at 13:50
  • don't put answers into the question but \begin{tabu} to \textwidth makes a full width table so you can not fit two (also the \caption forces a paragraph, you probably want two minipages each with a tabu and a caption) – David Carlisle May 29 at 13:54
3

This solution aligns the captions. Aligning the centers or first lines is relatively easy. Otherwise you may need to use \raisebox.

I also added a \columnsep gap between them.

\documentclass{article}
\usepackage{tabu}

\begin{document}
\begin{table}[htp]% 
\begin{minipage}[b]{\dimexpr 0.5\textwidth-0.5\columnsep}
    \small
    \begin{tabu} to \textwidth {  X[l] | X[c]  X[c]  X[c]  X[c]  X[c] }
%        \hline
        & \multicolumn{5}{c}{Precision} \\
%        \cline{5-6}
        & 0 & 1 & 2 & 3 & 4\\
        \hline
        A & 0.143 & 0.143 & & & \\
        B & 1.518 & 1.518 \\
        C & 0.018 & 0.142 \\
        D & 0.029 & 0.180 \\
        \hline
        \# tr samples & 53k, 187k & 53k, 187k & 53k, 187k \\
        \# te samples & 8k, 26k & \\
%        \hline
        \end{tabu}
    \medskip
    \caption{}
    \label{tab:runtime}
    \end{minipage}\hfill% add gap of \columnsep between tabus and captions
    \begin{minipage}[b]{\dimexpr 0.5\textwidth-0.5\columnsep}
    \small
    \begin{tabu} to \textwidth {  X[l] | X[c]  X[c]  X[c]  X[c]  X[c] }
%        \hline
        & \multicolumn{5}{c}{Precision} \\
%        \cline{5-6}
        & 0 & 1 & 2 & 3 & 4\\
        \hline
        A & 0.143 & 0.143 & & & \\
        B & 1.518 & 1.518 \\
        C & 0.018 & 0.142 \\
        D & 0.029 & 0.180 \\
        E & 0.029 & 0.180 \\
        F & 0.029 & 0.180 \\
%        \hline
        \end{tabu}
    \medskip
    \caption{}
    \label{tab:runtime}
\end{minipage}
\end{table}
\end{document}

demo

2

I prefer the following table design:

enter image description here

(red lines indicate text border)

\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs, tabularx}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
\begin{document}
\begin{table}[ht]
\small
    \begin{tabularx}{\linewidth}{@{} 
                    >{\hsize=1.1\hsize}X 
                    >{\hsize=0.9\hsize\raggedleft\arraybackslash}X @{}}
\caption{}
\label{tab:runtime}
\begin{tabular}[t]{@{} l*{5}{>{\centering\arraybackslash}p{2.5em}} @{}}
    \toprule
    & \multicolumn{5}{@{} c @{}}{Precision} \\
    \cmidrule{2-6}
    & 0 & 1 & 2 & 3 & 4\\
    \midrule
A               & 0.143     & 0.143     &           & & \\
B               & 1.518     & 1.518     &           & & \\
C               & 0.018     & 0.142     &           & & \\
D               & 0.029     & 0.180     &           & & \\
    \hline
\# tr samples   & 53k, 187k & 53k, 187k & 53k, 187k & & \\
\# te samples   & 8k, 26k   &           &           & & \\
    \bottomrule
    \end{tabular}
&
    \caption{}
    \label{tab:runtime} 
\begin{tabular}[t]{@{} l*{5}{>{\centering\arraybackslash}p{2.5em}} @{}}
    \toprule
    & \multicolumn{5}{@{} c @{}}{Precision with label shifted by t seconds } \\
    \cmidrule{2-6}
    & 0     & 1     & 2 & 3 & 4 \\
    \midrule
A   & 0.143 & 0.143 &   &   &   \\
B   & 1.518 & 1.518 &   &   &   \\
C   & 0.018 & 0.142 &   &   &   \\
D   & 0.029 & 0.180 &   &   &   \\
E   & 0.029 & 0.180 &   &   &   \\
F   & 0.029 & 0.180 &   &   &   \\
    \bottomrule
    \end{tabular}       
    \end{tabularx}
\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.