Latex: resize aligned tables

769 views Asked by At

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?

1

There are 1 answers

0
samcarter_is_at_topanswers.xyz On BEST ANSWER

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:

  • the indention at the start of the line is removed with \noindent

  • the minipages are resizes to .5\textwidth so they span the whole page

  • additional spacing before and after the columns is removed with @{}

  • % is used to avoid unprotected line endings which otherwise would act like spaces

  • if you like even more space between the tables, you could reduce the inter column spacing


\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