I am trying to do two tables side by side. I have also benefited from the following thread, followed this answer and a couple of others. Two tables side by side with minipage
My code is the following
\documentclass[preprint,12pt]{elsarticle}
\usepackage{lineno}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\graphicspath{{./Figures/}}
\usepackage{subfig}
\usepackage{floatrow}
\usepackage{dsfont}
\usepackage{float}
\usepackage[margin=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{slashbox}
\usepackage{subcaption}
\usepackage[showframe]{geometry}
\def \hfillx {\hspace*{-\textwidth} \hfill}
\begin{document}
\begin{table}[htb]
\begin{subtable}{.5\textwidth}
\tiny
\begin{tabular}{c c c c c}
Cluster & MAE & MSE & E[over] & E[under] \\
\hline
1 & 0.31 & 0.48 & 2.00 & 1.38 \\
2 & 0.32 & 0.49 & - & 1.36 \\
3 & 0.26 & 0.44 & 1.57 & 1.50\\
4 & 0.25 & 0.41 & 2.00 & 1.47 \\
\hline
\end{tabular}
\caption{Caption1 that is long}
\label{subtable:pr1rnn}
\end{subtable}%
\begin{subtable}{.5\textwidth}
\tiny
\begin{tabular}{c c c c c}
Cluster & MAE & MSE & E[over] & E[under] \\
\hline
1 & 0.40 & 0.59 & 1.50 & 1.28 \\
2 & 0.51 & 0.82 & 1.44 & 1.44 \\
3 & 0.53 & 0.77 & 1.31 & 1.31 \\
4 & 0.41 & 0.62 & 1.88 & 1.28 \\
\hline
\end{tabular}
\caption{Caption2 that is long}
\label{subtable:pr2rfres}
\end{subtable}
\end{table}
\end{document}
It gives me the following result:
I lose Caption 1 completely and the tables are not side-by-side. I tried to apply the answers from the related threads, but I can't seem to find where I am going wrong. How do I do them side by side?


subtableso your example code does not compile but instead show the error message:! Missing number, treated as zero.The correct usage is\begin{subtable}{<width>}with<width>={.5\textwidth}or any other length of your choice. – leandriis Jan 02 '19 at 19:47articleand a) the above described width, the desired layout is produced. If I complete the code b) without the width the above described error occurs. That said, I am not able to reproduce either of the outputs in your screenshots. – leandriis Jan 02 '19 at 20:09! Package subcaption Error: This package can't be used in cooperation (subcaption) with the subfig package.that tells you that the packagessubcaptionandsubfig(that you both load) are incompatible with each other. As you currently usesubcaption's syntax, simply remove thesubfigpackage from your preamble. Apart from that and unrelated to the problem, you load thegeometrypackage twice with different options which will also lead to an error. – leandriis Jan 02 '19 at 20:22subfigpackage affects them. Could I use these tables for subfigures? – A Doe Jan 02 '19 at 20:28subcaptionpackage offers thesubfigureenvironment for this. The usage is similar to thesubtableenvironment. – leandriis Jan 02 '19 at 20:30