将所有 4 个表格放在同一行

将所有 4 个表格放在同一行

我尝试使用“minipage”将所有 4 个表格放在同一行上。但是,它不起作用。我只能将小表格放在同一行上。我该如何解决?

答案1

以下代码可能可以实现您想要实现的目标。请注意\hfill表格之间三个间隙的使用;它确保四个表格占据了文本块的整个宽度。

在此处输入图片描述

\documentclass[a4paper,12pt]{article}
\usepackage[hmargin=2.5cm]{geometry}  % choose page margins here
\usepackage{booktabs} % for \toprule, \midrule, and \bottomrule macros

\newcommand\maketabular{%  %% macro for a repeated element
\begin{tabular}{lrrr}
\toprule
A & B & C & D \\
\midrule
15 & 20 & 30 & 40 \\
30 & 40 & 60 & 80 \\
\bottomrule
\end{tabular}} % end of \maketabular macro

\begin{document}
\begin{table}[h!]  % "[h!]" placement directive just for this example
\caption{Four side-by-side tables}
% increase the vertical separation between caption and tabular material
\medskip 

\maketabular
\hfill % for maximal horizonal separation between the tabular environments
\maketabular
\hfill
\maketabular
\hfill
\maketabular
\end{table}
\end{document}

相关内容