从顶部垂直对齐多个表格

从顶部垂直对齐多个表格

我需要

  1. 将所有四个表格对齐在顶部(目前看起来它们都按中心对齐)。
  2. 每个表中的“功能”之间都有垂直线分隔,以免被打断。
\documentclass[10pt]{article}
\textwidth= 5.00in
\textheight= 7.4in
\topmargin = 30pt
\evensidemargin=0pt
\oddsidemargin=55pt
\headsep=17pt
\parskip=.8pt
\parindent=12pt
\font\smallit=cmti10
\font\smalltt=cmtt10
\font\smallrm=cmr9

\usepackage{tabularx}
\usepackage{amssymb,amsmath,amsthm,enumitem} 
\usepackage{subcaption,booktabs}

\begin{document}

\begin{table}[h] 
\setlength\tabcolsep{0pt}
\small 
\caption{Examples} 
\label{tab:4subt_2}
\begin{subtable}{0.35\textwidth}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}ccccc|c}
\toprule
$aa$ & $bb$ & $cc$ & $dd$  & $ee$ & fu\\
\midrule
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
\hline
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
\bottomrule
\end{tabular*}
\end{subtable}
\hfill
\begin{subtable}{0.22\textwidth}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}ccccc|c}
\toprule
$aa$ & $bb$ & $cc$ & $dd$  & $ee$ & fu\\
\midrule
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
\hline
1 &2 &3 &4 &5  & 1, 2, 3\\
\hline
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
\hline
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
\bottomrule
\end{tabular*}
\end{subtable}
\hfill
\begin{subtable}{0.2\textwidth}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}ccccc|c}
\toprule
$aa$ & $bb$ & $cc$ & $dd$  & $ee$ & fu\\
\midrule
1 &2 &3 &4 &5  & 1, 2\\
1 &2 &3 &4 &5  & 1, 2\\
1 &2 &3 &4 &5  & 1, 2\\
\hline
1 &2 &3 &4 &5  & 1, 2\\
\bottomrule
\end{tabular*}
\end{subtable}
\hfill
\begin{subtable}{0.18\textwidth}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}ccccc|c} 
\toprule
$aa$ & $bb$ & $cc$ & $dd$  & $ee$ & fu\\
\midrule
1 &2 &3 &4 &5  & 1\\
1 &2 &3 &4 &5  & 1\\
\bottomrule
\end{tabular*}
\end{subtable}
\hfill
\end{table}
\end{document}

答案1

正如@DavidCarlisle 在评论中所建议的那样,只需将所有四个实例更改为

\begin{tabular*}{\linewidth}

\begin{tabular*}{\linewidth}[t]

对齐t说明符告诉 LaTeX 四个tabular*环境应该沿着它们的顶线对齐。

顺便说一句,在设置为零的tabular*环境中采用垂直规则根本不是一个好主意。\tabcolsep

在此处输入图片描述

\documentclass[10pt]{article}
\textwidth= 5.00in
\textheight= 7.4in
\topmargin = 30pt
\evensidemargin=0pt
\oddsidemargin=55pt
\headsep=17pt
\parskip=.8pt
\parindent=12pt
%\font\smallit=cmti10
%\font\smalltt=cmtt10
%\font\smallrm=cmr9

\usepackage{tabularx}
\usepackage{amssymb,amsmath,amsthm,enumitem} 
\usepackage{subcaption,booktabs}

\begin{document}

\begin{table}[h] 
\setlength\tabcolsep{0pt}
\small 
\caption{Examples} 
\label{tab:4subt_2}
\begin{subtable}{0.35\textwidth}
\begin{tabular*}{\linewidth}[t]{@{\extracolsep{\fill}}ccccc|c}
\toprule
$aa$ & $bb$ & $cc$ & $dd$  & $ee$ & fu\\
\midrule
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
\hline
1& 2& 3& 4& 5& $1,2,3,4 = [5] \setminus \{6\}$\\
\bottomrule
\end{tabular*}
\end{subtable}%
\hfill
\begin{subtable}{0.22\textwidth}
\begin{tabular*}{\linewidth}[t]{@{\extracolsep{\fill}}ccccc|c}
\toprule
$aa$ & $bb$ & $cc$ & $dd$  & $ee$ & fu\\
\midrule
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
\hline
1 &2 &3 &4 &5  & 1, 2, 3\\
\hline
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
\hline
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
\bottomrule
\end{tabular*}
\end{subtable}%
\hfill
\begin{subtable}{0.2\textwidth}
\begin{tabular*}{\linewidth}[t]{@{\extracolsep{\fill}}ccccc|c}
\toprule
$aa$ & $bb$ & $cc$ & $dd$  & $ee$ & fu\\
\midrule
1 &2 &3 &4 &5  & 1, 2\\
1 &2 &3 &4 &5  & 1, 2\\
1 &2 &3 &4 &5  & 1, 2\\
\hline
1 &2 &3 &4 &5  & 1, 2\\
\bottomrule
\end{tabular*}
\end{subtable}%
\hfill
\begin{subtable}{0.18\textwidth}
\begin{tabular*}{\linewidth}[t]{@{\extracolsep{\fill}}ccccc|c} 
\toprule
$aa$ & $bb$ & $cc$ & $dd$  & $ee$ & fu\\
\midrule
1 &2 &3 &4 &5  & 1\\
1 &2 &3 &4 &5  & 1\\
\bottomrule
\end{tabular*}
\end{subtable}%
\hfill
\end{table}
\end{document}

答案2

  • 包中定义的规则booktabs不适用于带有垂直线的表格。
  • 为了消除这些间隙,您有几种方法。例如,重新定义规则并通过使用包添加垂直空间cellspace,...或使用tabularray如下所示的包:
\documentclass{article}
\textwidth= 5.00in
\textheight= 7.4in
\topmargin = 30pt
\evensidemargin=0pt
\oddsidemargin=55pt
\headsep=17pt
\parskip=.8pt
\parindent=12pt

\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs}
\usepackage{amssymb,amsthm,enumitem}
\usepackage{subcaption}

\begin{document}

\begin{table}[ht]
\setlength\tabcolsep{0pt}
\small
\caption{Examples}
\label{tab:4subt_2}
\begin{subtable}{0.36\textwidth}
\begin{tblr}[t]{colsep= 2pt,
             colspec = {@{} *{5}{X[c]}|Q[c,mode=math] @{}},
             row{1}  = {mode=math}
             }
    \toprule
aa & bb & cc & dd  & ee & \text{fu}\\
    \midrule
1   & 2 & 3 & 4 & 5 & 1,2,3,4 = [5] \setminus \{6\}    \\
1   & 2 & 3 & 4 & 5 & 1,2,3,4 = [5] \setminus \{6\}    \\
1   & 2 & 3 & 4 & 5 & 1,2,3,4 = [5] \setminus \{6\}    \\
1   & 2 & 3 & 4 & 5 & 1,2,3,4 = [5] \setminus \{6\}    \\
1   & 2 & 3 & 4 & 5 & 1,2,3,4 = [5] \setminus \{6\}    \\
    \hline
1   & 2 & 3 & 4 & 5 & 1,2,3,4 = [5] \setminus \{6\}     \\
    \bottomrule
\end{tblr}
\end{subtable}%
\hfill
\begin{subtable}{0.23\textwidth}
\begin{tblr}[t]{colsep= 2pt,
             colspec = {@{} *{5}{X[c]}|c @{}},
             row{1}  = {mode=math}
             }
    \toprule
aa & bb & cc & dd  & ee & \text{fu} \\
    \midrule
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
    \hline
1 &2 &3 &4 &5  & 1, 2, 3\\
\hline
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
    \hline
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
1 &2 &3 &4 &5  & 1, 2, 3\\
    \bottomrule
\end{tblr}
\end{subtable}%
\hfill
\begin{subtable}{0.20\textwidth}
\begin{tblr}[t]{colsep= 2pt,
             colspec = {@{} *{5}{X[c]}|c @{}},
             row{1}  = {mode=math}
             }
    \toprule
aa & bb & cc & dd  & ee & \text{fu}   \\
    \midrule
1 &2 &3 &4 &5  & 1, 2\\
1 &2 &3 &4 &5  & 1, 2\\
1 &2 &3 &4 &5  & 1, 2\\
    \hline
1 &2 &3 &4 &5  & 1, 2\\
    \bottomrule
\end{tblr}
\end{subtable}%
\hfill
\begin{subtable}{0.18\textwidth}
\begin{tblr}[t]{colsep= 2pt,
             colspec = {@{} *{5}{X[c]}|c @{}},
             row{1}  = {mode=math}
             }
    \toprule
aa & bb & cc & dd  & ee & \text{fu}\\
    \midrule
1 &2 &3 &4 &5  & 1\\
1 &2 &3 &4 &5  & 1\\
    \bottomrule
\end{tblr}
\end{subtable}
    \end{table}
\end{document}

在此处输入图片描述

相关内容