3

I want to put two tables side by side and my I have included a sample code below. How can we put separate captions for two tables in LaTeX included in one tabular environment?

\documentclass{article}
\begin{document}

\begin{tabular}{ll}
\begin{tabular}{ccc}
A & B & C \\
\cline{1-3}
1 & 2 & 3 \\
\cline{1-3}
C & B & A \\
\end{tabular}
&
\begin{tabular}{ccc}
D & E & F \\
\cline{1-3}
4 & 5 & 6 \\
\cline{1-3}
F & E & D \\
\end{tabular}
\end{tabular}
\end{document}
New contributor
Brown is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
4

using tabularx for outer table and use table environment:

\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}
    \begin{table}[htb]
\begin{tabularx}{\linewidth}{CC}
\caption{The first table}
    \begin{tabular}{ccc}
    A & B & C \\
    \cline{1-3}
    1 & 2 & 3 \\
    \cline{1-3}
    C & B & A \\
    \end{tabular}
&
\caption{The second table}
    \begin{tabular}{ccc}
    D & E & F \\
    \cline{1-3}
    4 & 5 & 6 \\
    \cline{1-3}
    F & E & D \\
    \end{tabular}
\end{tabularx}
    \end{table}
\end{document}

enter image description here

addendum: in cases, when one table is wider than other and wider than the column width, you can manually accommodate columns width of the outer table. for this is more appropriate to use tabular* than tabularx table environment:

\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\usepackage{lipsum}

\begin{document}
\lipsum[1]
    \begin{table*} 
\begin{tabular*}{\linewidth}{C{\dimexpr0.3\linewidth-2\tabcolsep}
                             C{\dimexpr0.7\linewidth-2\tabcolsep}}
\caption{The first table}
    \begin{tabular}{ccc}
    \hline
    A & B & C \\
    \hline
    1 & 2 & 3 \\
    C & B & A \\
    \hline
    \end{tabular}
&
\caption{The second table}
    \begin{tabular}{*{14}{c}}
    \hline
    D & E & F & G & H & I & J & D & E & F & G & H & I & J   \\
    \hline
    4 & 5 & 6 & 7 & 8 & 9 & 0 & 4 & 5 & 6 & 7 & 8 & 9 & 0   \\
    J & I & H & G & F & E & D & J & I & H & G & F & E & D   \\
    \hline
    \end{tabular}
\end{tabular*}
    \end{table*}
\lipsum\lipsum
\end{document}

which gives:

enter image description here

  • This is very good but the problem what happens when Table I has a lot more columns than Table II. How do handle the space and I want these two tables to be placed at the top of a two-column article using \begin{table*} – Brown Apr 15 at 20:31
  • 1
    @Brown, see addendum to answer. – Zarko Apr 16 at 0:03
  • You are awesome and thank you so much. I have marked your answer as ACCEPTED! – Brown Apr 16 at 10:51
  • @Brown, you are welcome! – Zarko Apr 16 at 10:53
2

With minipages and captionof you can achieve the following:

enter image description here

\documentclass{article}
\usepackage{capt-of}
\begin{document}
\noindent
\begin{minipage}{0.5\textwidth}
\centering
\begin{tabular}{ccc}
A & B & C \\
\cline{1-3}
1 & 2 & 3 \\
\cline{1-3}
C & B & A \\
\end{tabular}
\captionof{table}{My first caption}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\begin{tabular}{ccc}
D & E & F \\
\cline{1-3}
4 & 5 & 6 \\
\cline{1-3}
F & E & D \\
\end{tabular}
\captionof{table}{My second caption}
\end{minipage}
\end{document}
2

You can use the floatrow package:

\documentclass{article}
\usepackage{caption}
\usepackage{floatrow}

\begin{document}

\begin{table}
\captionsetup{justification=raggedright}
\floatsetup{captionskip=2pt}
\begin{floatrow}
\ttabbox[1.4\FBwidth]{\caption{A First Table}}{\begin{tabular}{ccc}
A & B & C \\
\cline{1-3}
1 & 2 & 3 \\
\cline{1-3}
C & B & A \\
\end{tabular}}

\ttabbox[1.4\FBwidth]{\caption{A Second Table}}{\begin{tabular}{ccc}
D & E & F \\
\cline{1-3}
4 & 5 & 6 \\
\cline{1-3}
F & E & D \\
\end{tabular}}
\end{floatrow}
\end{table}

\end{document} 

enter image description here

  • I am getting this error Package floatrow Error: Do not use float package with floatrow. – Brown Apr 15 at 20:28
  • Yes, because floatrow redefines the H specifier for its own sake, and a few other things. So if you load float for ‘H’, you can use it with only floatrow. – Bernard Apr 15 at 21:17
  • It means there is no way to get around this. But thank you! – Brown Apr 15 at 21:28

Your Answer

Brown is a new contributor. Be nice, and check out our Code of Conduct.

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.