How to insert two and multiple tables side by side in LaTeX?

Welcome to a beautiful tutorial. This tutorial contains solutions to all types of questions on inserting two tables side by side.

When inserting two or more tables side by side, many kinds of problems have to be faced. For example, how to add captions to the entire environment with subtables? And how to insert two tables of different heights side by side?

In addition to height, you can insert two tables with different widths.

Use minipage environment

As I discussed earlier in Figure, when you insert two float elements side by side, you create two spaces before them. After that insert the tables in this space.

For example, notice the code below where this task is completed by the minipage environment.

\documentclass[12pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{xcolor,lipsum,subcaption}
\begin{document}
\pagecolor{red!15}
\lipsum[1][1-8]

\vspace{.5cm}

\begin{minipage}{.4\textwidth}
  \centering
    \begin{tabular}{|c|c|c|c|c|}
    \hline
    A11 & A12 & A13 & A14 & A15\\
    \hline
    A21 & A22 & A23 & A24 & A15\\
    \hline
    A31 & A32 & A33 & A34 & A15\\
    \hline
    A41 & A42 & A43 & A44 & A15\\
    \hline
    \end{tabular}
  \captionof{table}{First Table}
\end{minipage}%
\begin{minipage}{.5\textwidth}
  \centering
  \begin{tabular}{|c|c|c|c|c|}
    \hline
      1 & 2 & 3 & 4 & 5\\
    \hline
    A & B & C & D & F\\ 
    \hline
    AA & BB & CC & DD & FF\\
    \hline
    AAA & BBB & CCC & DDD & FFF\\
    \hline
    AAAA & BBBB & CCCC & DDDD & FFFF\\
    \hline
  \end{tabular}
\captionof{table}{Second Table}
\end{minipage}

\vspace{.5cm}

\lipsum[2][1-7]

\vspace{.5cm}

\noindent
\begin{minipage}{0.33\textwidth}
    \centering
    \begin{tabular}{|c|c|c|c|}
    \hline
    A11 & A12 & A13 & A14 \\
    \hline
    A21 & A22 & A23 & A24 \\
    \hline
    A31 & A32 & A33 & A34 \\
    \hline
    A41 & A42 & A43 & A44 \\
    \hline
    \end{tabular}
    \captionof{table}{First Table}
\end{minipage}%
\begin{minipage}{0.33\textwidth}
    \centering
    \begin{tabular}{|c|c|c|c|}
      \hline
      B11 & B12 & B13 & B14 \\
      \hline
      B21 & B22 & B23 & B24 \\
      \hline
      B31 & B32 & B33 & B34 \\
      \hline
      B41 & B42 & B43 & B44 \\
      \hline
    \end{tabular}
    \captionof{table}{Second Table}
\end{minipage}%
\begin{minipage}{0.33\textwidth}
    \centering
    \begin{tabular}{|c|c|c|c|}
      \hline
      C11 & C12 & C13 & C14 \\
      \hline
      C21 & C22 & C23 & C24 \\
      \hline
      C31 & C32 & C33 & C34 \\
      \hline
      C41 & C42 & C43 & C44 \\
      \hline
    \end{tabular}
    \captionof{table}{Second Table}
\end{minipage}

\vspace{.5cm}

\lipsum[3][2-8]

\vspace{.5cm}

\noindent
\begin{minipage}{0.25\textwidth}
    \centering
    \begin{tabular}{|c|c|c|}
    \hline
    A11 & A12 & A13 \\
    \hline
    A21 & A22 & A23 \\
    \hline
    A31 & A32 & A33 \\
    \hline
    A41 & A42 & A43 \\
    \hline
    \end{tabular}
\end{minipage}%
\begin{minipage}{0.25\textwidth}
    \centering
    \begin{tabular}{|c|c|c|}
    \hline
    B11 & B12 & B13 \\
    \hline
    B21 & B22 & B23 \\
    \hline
    B31 & B32 & B33 \\
    \hline
    B41 & B42 & B43 \\
    \hline
    \end{tabular}
\end{minipage}%
\begin{minipage}{0.25\textwidth}
    \centering
    \begin{tabular}{|c|c|c|}
    \hline
    C11 & C12 & C13 \\
    \hline
    C21 & C22 & C23 \\
    \hline
    C31 & C32 & C33 \\
    \hline
    C41 & C42 & C43 \\
    \hline
    \end{tabular}
\end{minipage}%
\begin{minipage}{0.25\textwidth}
    \centering
    \begin{tabular}{|c|c|c|c|}
    \hline
    D11 & D12 & D13 \\
    \hline
    D21 & D22 & D23 \\
    \hline
    D31 & D32 & D33 \\
    \hline
    D41 & D42 & D43 \\
    \hline
    \end{tabular}
\end{minipage}

\vspace{.5cm}

\lipsum[3][2-8]

\vspace{.5cm}

\begin{minipage}{.35\textwidth}
  \centering
    \begin{tabular}{|c|c|c|c|c|}
    \hline
    A11 & A12 & A13 & A14 & A15\\
    \hline
    A21 & A22 & A23 & A24 & A15\\
    \hline
    A31 & A32 & A33 & A34 & A15\\
    \hline
    A41 & A42 & A43 & A44 & A15\\
    \hline
    \end{tabular}
  \captionof{table}{First Table}
\end{minipage}%
\begin{minipage}{.60\textwidth}
  \centering
    \begin{tabular}{|c|c|c|c|c|c|}
    \hline
    Data11 & Data12 & Data13 & Data14 & Data15 & Data16 \\
    \hline
    Data21 & Data22 & Data23 & Data24 & Data25 & Data26 \\
    \hline
    Data31 & Data32 & Data33 & Data34 & Data35 & Data36 \\
    \hline
    Data41 & Data42 & Data43 & Data44 & Data45 & Data46 \\
    \hline
    Data51 & Data52 & Data53 & Data54 & Data55 & Data56 \\
    \hline
    Data61 & Data62 & Data63 & Data64 & Data65 & Data66 \\
    \hline
    \end{tabular}
\captionof{table}{Second Table}
\end{minipage}

\end{document}

Output :

To add subcaption, the subcaption package is used which contains \captionof commands. According to the width of table, the width of minipage is unequal, so the error does not show.

In the case of minipage, when two tables of unequal height are inserted side by side, their vertical position will be middle.

Use subtable Environment from subcaption package

Our second method is to use the subtable environment. Its syntax is exactly like minipage. The amount of space reserved for each subtable is defined by the \lenthwidth length variable.

\documentclass[12pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{subcaption,xcolor,lipsum}
\begin{document}
\pagecolor{yellow!20}
\lipsum[1][4-9]

\begin{table}[h]
\centering
 \begin{subtable}[b]{0.45\linewidth}
    \centering
      \begin{tabular}{|c|c|c|c|}
        \hline
         A11 & A12 & A13 & A14 \\
        \hline
         A21 & A22 & A23 & A24 \\
         \hline
         A31 & A32 & A33 & A34 \\
         \hline
          A41 & A42 & A43 & A44 \\
          \hline
          A51 & A52 & A53 & A54 \\
          \hline
       \end{tabular}
       \caption{First Subtable}
    \end{subtable}%
 \begin{subtable}[b]{0.45\linewidth}
        \centering
        \begin{tabular}{|c|c|c|c|c|}
            \hline
            A & B & C & D & E\\
            \hline
            1 & 2 & 3 & 4 & 5\\
            \hline
            11 & 22 & 33 & 44 & 55\\
            \hline
        \end{tabular}
        \caption{Second Subtable}
    \end{subtable}
    \caption{Main Table Caption}
\end{table}

\lipsum[3][1-9]

\begin{table}[h]
    \centering
    \begin{subtable}{0.30\linewidth}
        \centering
        \begin{tabular}{|c|c|c|c|}
        \hline
        A11 & A12 & A13 & A14 \\
        \hline
        A21 & A22 & A23 & A24 \\
        \hline
        A31 & A32 & A33 & A34 \\
        \hline
        A41 & A42 & A43 & A44 \\
        \hline
        \end{tabular}
        \caption{Subtable A}
    \end{subtable}%
    \begin{subtable}{0.23\linewidth}
        \centering
        \begin{tabular}{|c|c|c|}
        \hline
        B11 & B12 & B13 \\
        \hline
        B21 & B22 & B23  \\
        \hline
        B31 & B32 & B33  \\
        \hline
        B41 & B42 & B43  \\
        \hline
        \end{tabular}
        \caption{Subtable B}
    \end{subtable}%
    \begin{subtable}{0.23\linewidth}
        \centering
        \begin{tabular}{|c|c|c|}
        \hline
        C11 & C12 & C13 \\
        \hline
        C21 & C22 & C23 \\
        \hline
        C31 & C32 & C33 \\
        \hline
        C41 & C42 & C43 \\
        \hline
        \end{tabular}
        \caption{Subtable C}
    \end{subtable}%
    \begin{subtable}{0.23\linewidth}
        \centering
        \begin{tabular}{|c|c|c|}
        \hline
        D11 & D12 & D13 \\
        \hline
        D21 & D22 & D23 \\
        \hline
        D31 & D32 & D33 \\
        \hline
        D41 & D42 & D43 \\
        \hline
        \end{tabular}
        \caption{Subtable D}
    \end{subtable}

    \caption{Main Table with Subtables}
    \label{tab:main}
\end{table}

\lipsum[4][1-9]

\end{document}

Output :

For captions, use the subtitle package. And vertically positioned will be the bottom.

Insert sub-tables inside another table

If you want, you can insert two or more tables side by side into one table. For example

\documentclass[12pt]{article}
\usepackage[margin=1.5cm]{geometry}
\usepackage{subcaption,lipsum,xcolor}
\begin{document}
\pagecolor{lime!15}

\lipsum[1][1-9]

\begin{table}[h]
    \centering
    \begin{tabular}{c c}
        % First table
        \begin{tabular}{|c|c|c|c|}
            \hline
            A & B & C & D \\
            \hline
            1 & 2 & 3 & 4 \\
            \hline
            11 & 22 & 33 & 44 \\
            \hline
            110 & 220 & 330 & 440 \\
            \hline
        \end{tabular}
        &
        % Second table
        \begin{tabular}{|c|c|c|c|}
            \hline
            E & F & G & H \\
            \hline
            5 & 6 & 7 & 8  \\
            \hline
            55 & 66 & 77 & 88 \\
            \hline
        \end{tabular}  
    \end{tabular}
    \caption{Side by Side Tables}
\end{table}

\lipsum[2][1-8]

\begin{table}[h]
    \centering
    \begin{tabular}{c c c}
        % First table
        \begin{tabular}{|c|c|c|c|}
            \hline
            A & B & C & D \\
            \hline
            1 & 2 & 3 & 4 \\
            \hline
            11 & 22 & 33 & 44 \\
            \hline
        \end{tabular}
        &
        % Second table
        \begin{tabular}{|c|c|c|c|}
            \hline
            E & F & G & H \\
            \hline
            5 & 6 & 7 & 8  \\
            \hline
            55 & 66 & 77 & 88 \\
            \hline
        \end{tabular}  
        &
        % Second table
        \begin{tabular}{|c|c|c|c|}
            \hline
            I & J & K & L \\
            \hline
            9 & 10 & 11 & 12  \\
            \hline
            99 & 110 & 121 & 132 \\
            \hline
        \end{tabular} \\
        table 1 & table 2 & table 3
        
    \end{tabular}
    \caption{Side by Side Tables}
\end{table}

\lipsum[3][1-9]

\end{document}

Output :

For the caption, you can define another row below. I think this is not the best method but it is good to know how to place one or more tables within a table.

Best practice

1. This process is very simple, first create space for the float element, then insert the float element into that space.

2. You need to know the concept and usage of length variables like \textwidth and \linewidth. Then it will be very easy for you to insert float elements side by side.

3. minipage approach provides more flexibility in terms of spacing between tables. You can easily adjust the spacing by modifying the width of minipage and using \hfill or other spacing commands.

Conclusion

There are multiple ways to position tables side-by-side in LaTeX. These methods include using minipage environment, subtable environment from subcaption package, or directly within the tabular environment itself.

Md Jidan Mondal

LaTeX expert with over 10 years of experience in document preparation and typesetting. Specializes in creating professional documents, reports, and presentations using LaTeX.

Leave a Comment

Your email address will not be published. Required fields are marked *