latexsubcaption

Latex: resize aligned tables


I'm trying to horizontally align two tables using the package subcaption:

\documentclass[12pt, a4paper]{article}
\usepackage{graphicx} 
\usepackage{tabularx}
\usepackage{subcaption}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\begin{minipage}[c]{0.4\textwidth}
\centering
\captionof{table}{table no. 1}
\begin{tabular}{cccc}
              & 1 & 2 & 3 \\
    \hline
    Number1 & 10550 & 95767 & 867835 \\
    Number2 & 1000 & 455653 & 56467 \\ 
    \hline
    Number1 & 7566 & 6776 & 56657 \\
    Number2 & 5646 & 56765 & 67668 \\
    \hline
    \end{tabular}
\end{minipage}
\begin{minipage}[c]{0.4\textwidth}
\centering
\captionof{table}{table no. 2}
\begin{tabular}{cccc}
              & 1 & 2 & 3 \\
    \hline
    Number1 & 44760 & 97567 & 857835 \\
    Number2 & 13200 & 46653 & 5756 \\ 
    \hline
    Number1 & 75666 & 66776 & 5654657 \\
    Number2 & 5646 & 57665 & 676685 \\
    \hline
    \end{tabular}
\end{minipage}
\end{document}

but the two tables end up overlapping:

enter image description here

Is there a way to resize the tables to avoid the overlap?


Solution

  • In general you should rather use a suitable font size instead of resizing elements which contain text.

    However in your case, resizing is not necessary. The tables will fit if:


    \documentclass[12pt, a4paper]{article}
    \usepackage{graphicx} 
    \usepackage{tabularx}
    \usepackage{subcaption}
    \usepackage{amsmath}
    \usepackage{amssymb}
    
    \begin{document}
    
    \noindent\begin{minipage}[c]{0.5\textwidth}
    \centering
    \captionof{table}{table no. 1}
    \begin{tabular}{@{}cccc@{}}
                  & 1 & 2 & 3 \\
        \hline
        Number1 & 10550 & 95767 & 867835 \\
        Number2 & 1000 & 455653 & 56467 \\ 
        \hline
        Number1 & 7566 & 6776 & 56657 \\
        Number2 & 5646 & 56765 & 67668 \\
        \hline
        \end{tabular}
        \hfill%
    \end{minipage}%
    \begin{minipage}[c]{0.5\textwidth}
    \centering
    \captionof{table}{table no. 2}
        \hfill%
    \begin{tabular}{@{}cccc@{}}
                  & 1 & 2 & 3 \\
        \hline
        Number1 & 44760 & 97567 & 857835 \\
        Number2 & 13200 & 46653 & 5756 \\ 
        \hline
        Number1 & 75666 & 66776 & 5654657 \\
        Number2 & 5646 & 57665 & 676685 \\
        \hline
        \end{tabular}
    \end{minipage}%
    
    \end{document}
    

    enter image description here