将四张表格并排放置在一张大表格内,大表格顶部有标题,小表格下方有小标题

将四张表格并排放置在一张大表格内,大表格顶部有标题,小表格下方有小标题

我需要一张顶部带有标题的表格。表格内应该有四张小表格,按照当前位置并排摆放。

\documentclass[10pt]{article}
\textwidth= 5.00in
\textheight= 7.4in
\topmargin = 30pt
\evensidemargin=0pt
\oddsidemargin=55pt
\headsep=17pt
\parskip=.5pt
\parindent=12pt


\usepackage{tabularx}
\usepackage{amssymb,latexsym,amsmath,epsfig,amsthm,enumerate} %% Add other packages as necessary
\newcolumntype{P}[1]{%
  p{\dimexpr#1\linewidth-2\tabcolsep-1.3333\arrayrulewidth}}

\begin{document}

Let us consider a few examples. The examples are shown in the tables below. The descriptions have to be below each table.

\footnotesize

\begin{tabular}{|P{0.04}P{0.04}P{0.04}P{0.045}|P{0.04}|}
\hline
$a_1$ & $a_2$ & $a_3$ & $a_4$  &  fg \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
\end{tabular}
\quad
\begin{tabular}{|P{0.04}P{0.04}P{0.04}P{0.045}|P{0.04}|}
\hline
$a_1$ & $a_2$ & $a_3$ & $a_4$  &  fg \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
\end{tabular}
\quad
\begin{tabular}{|P{0.04}P{0.04}P{0.04}P{0.045}|P{0.04}|}
\hline
$a_1$ & $a_2$ & $a_3$ & $a_4$  &  fg \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
\end{tabular}
\quad
\begin{tabular}{|P{0.04}P{0.04}P{0.04}P{0.045}|P{0.04}|}
\hline
$a_1$ & $a_2$ & $a_3$ & $a_4$  &  fg \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\hline
\end{tabular}

\bigskip 

\normalfont
Check if the font is back to normal.

\end{document}

在此处输入图片描述

我的问题是

  1. 如果我启动 \begin{table} ... \end{table} 并将所有表格都包含在内,表格就会发生移动。它们不再彼此相邻。
  2. 我需要在每个小表格下添加注释,比如“ex 1”,“ex 2”,“ex 3”,“ex 4”,但在开头的单词 Table 带有与所有小表格相对应的标题。
  3. 在我的表格之后字体并没有恢复正常。即使我写了 \normalfont。

答案1

像这样吗?

在此处输入图片描述

\documentclass[10pt]{article}
\textwidth= 5.00in
\textheight= 7.4in
\topmargin = 30pt
\evensidemargin=0pt
\oddsidemargin=55pt
\headsep=17pt

\parskip=.5pt % that'll be barely noticeable...
\parindent=12pt


\usepackage{array}
\usepackage{amssymb,%latexsym,
            amsmath,
            graphicx,%epsfig,
            amsthm,
            enumitem%enumerate
           }
\usepackage{subcaption,booktabs}


\begin{document}

\begin{table}[htbp]
\setlength\tabcolsep{0pt} % let LaTeX figure out intercol. whitespace
\small % 10% linear reduction in font size

\caption{A table with four subtables} 
\label{tab:4subt}

\begin{subtable}{0.22\textwidth}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}ccccc} 
\toprule
$a_1$ & $a_2$ & $a_3$ & $a_4$ & fg \\
\midrule
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\addlinespace
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\addlinespace
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\bottomrule
\end{tabular*}
\caption{ex 1} \label{tab:sub1}
\end{subtable}%
\hfill
\begin{subtable}{0.22\textwidth}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}ccccc}
\toprule
$a_1$ & $a_2$ & $a_3$ & $a_4$ & fg \\
\midrule
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\addlinespace
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\addlinespace
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\bottomrule
\end{tabular*}
\caption{ex 2} \label{tab:sub2}
\end{subtable}%
\hfill
\begin{subtable}{0.22\textwidth}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}ccccc}
\toprule
$a_1$ & $a_2$ & $a_3$ & $a_4$ & fg \\
\midrule
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\addlinespace
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\addlinespace
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\bottomrule
\end{tabular*}
\caption{ex 3} \label{tab:sub3}
\end{subtable}%
\hfill
\begin{subtable}{0.22\textwidth}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}ccccc}
\toprule
$a_1$ & $a_2$ & $a_3$ & $a_4$ & fg \\
\midrule
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\addlinespace
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\addlinespace
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
10 &  10 &  10  & 10  &  10  \\
\bottomrule
\end{tabular*}
\caption{ex 4} \label{tab:sub4}
\end{subtable}

\end{table}

\end{document}

答案2

\subfloat3.1 版或更高版本中定义的替代方案subcaption,以及使用tabularray包。使用它们,代码会短一点:

\documentclass{article}
\textwidth= 5.00in
\textheight= 7.4in
\topmargin = 30pt
\evensidemargin=0pt
\oddsidemargin=55pt
\headsep=17pt
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
  \ExplSyntaxOn
\NewChildSelector{eachthree}
  {
    \int_step_inline:nnnn {1}{3}{\l_tblr_childs_total_tl}
      { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
  }
  \ExplSyntaxOff
\usepackage[skip=1ex]{caption}
\usepackage{subcaption}


\begin{document}
    \begin{table}[htbp]
\caption{A table with four subtables}
\label{tab:4subt}
\subcaptionsetup[table]{labelformat=empty,
                        position=bottom, 
                        skip=0.5ex}
\small % 10% linear reduction in font size

\SetTblrInner{width=0.22\linewidth, % subtables common settings
              colsep  = 3pt,
              row{1}  = {mode=math},
              row{2-Z}= {rowsep=1pt},
              row{eachthree} = {belowsep=1ex},
              row{Z}  = {belowsep+=-1ex}
              }
\centering%
\subfloat[ex 1  \label{tab:sub1}]
{%
\begin{tblr}{colspec = {@{} *{5}{X[c]} @{}}}            
    \toprule
a_1& a_2 & a_3 & a_4 & fg   \\
    \midrule
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
%
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
%
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
    \bottomrule
\end{tblr}}\hfill%
\subfloat[ex 2  \label{tab:sub2}]
{%
\begin{tblr}{colspec = {@{} *{5}{X[c]} @{}}}
    \toprule
a_1& a_2 & a_3 & a_4 & fg   \\
    \midrule
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
%
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
%
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
    \bottomrule
\end{tblr}}\hfill%
\subfloat[ex 3  \label{tab:sub3}]
{%
\begin{tblr}{colspec = {@{} *{5}{X[c]} @{}}}
    \toprule
a_1& a_2 & a_3 & a_4 & fg   \\
    \midrule
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
%
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
%
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
    \bottomrule
\end{tblr}}\hfill%
\subfloat[ex 4  \label{tab:sub4}]
{%
\begin{tblr}{colspec = {@{} *{5}{X[c]} @{}}}
    \toprule
a_1& a_2 & a_3 & a_4 & fg   \\
    \midrule
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
%
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
%
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
10 & 10  & 10  & 10  & 10   \\
    \bottomrule
\end{tblr}}
    \end{table}
\end{document}

在此处输入图片描述

(红线表示页面布局)

相关内容