如何对齐两个分组的表格,使它们全部与子标题一起在顶部对齐?

如何对齐两个分组的表格,使它们全部与子标题一起在顶部对齐?

我希望我的表格像这样对齐。 在此处输入图片描述

虽然有这个分组和标题

在此处输入图片描述

我只知道子浮点数 (subfloat),它有点烦人。

\documentclass{article}
\usepackage{subcaption}
\usepackage{float,subfloat}
\usepackage{graphicx}
\usepackage{caption}



\begin{document}


\begin{table}[h]
    \centering

\resizebox{\textwidth}{!}{
    \subfloat[Caption 1]{
        \begin{tabular}[t]{l|r}
        Koep & Abundance \\\hline
        Dfb &   167 \\
        Cfa &   150 \\
        BSk &   121 \\
        Dfc &   112 \\
        Csb &   106 \\
        Dsb &    56 \\
        Csa &    54 \\
        Dfa &    23 \\
        ET  &    17 \\
        Dsc &    15 \\
        Bwk &    15 \\
        Cfb &    14 \\
        Bwh &     5 \\
        Bsh &     4 \\
        Cfc &     4 \\
        Am  &     1 \\
        Aw  &     1 
        \end{tabular}
        \begin{tabular}[t]{l|r}
        Koep &  Abundance \\\hline
        Dfb &    34 \\
        Cfa &    31 \\
        BSk &    30 \\
        Csa &    29 \\
        Dfc &    29 \\
        Csb &    23 \\
        Dsb &    17 \\
        Dfa &    11 \\
        Cfb &     2 \\
        ET  &     2 \\
        Bsh &     2 \\
        Dwa &     2 \\
        Bwh &     1 \\
        Dsc &     1 
        \end{tabular}}
    \quad
    \subfloat[caption 2]{
        \begin{tabular}[t]{l|r}
        Land Cover & Abundance\\\hline
        Grasslands           &    355 \\
        Savannah's             &    136 \\
        Woody Savannah's         &    120 \\
        Croplands            &    104 \\
        Deciduous Brdlf Frsts   &     44 \\
        Open Shrublands       &     37 \\
        Evergreen Ndllf Frsts  &     32 \\
        Mixed Frsts          &     21 \\
        Barren               &      7 \\
        Cropland/Veg Mosaic  &      3 \\
        Urban and Built-up     &      2 \\
        Evergreen Brdlf Frsts &      2 \\
        Closed Shrublands      &      2 
        \end{tabular}
        \begin{tabular}[t]{l|r}
        Land Cover  &  Abundance \\\hline
        Grasslands           &     94 \\
        Savannah's             &     32 \\
        Croplands            &     31 \\
        Woody Savannah's          &     27 \\
        Deciduous Brdlf Frsts   &      8 \\
        Evergreen Brdlf Frsts  &      8 \\
        Open Shrublands       &      6 \\
        Mixed Frsts          &      4 \\
        Cropland/Veg Mosaic  &      2 \\
        Evergreen Brdlf Frsts &      1 \\
        Urban and Built-up     &      1 
        \end{tabular}}}
\centering
\caption{Caption }\label{tab:sec}
\end{table}

\end{document}

答案1

使用subcaption,您可以先使用 选项在两个subtable环境中编写表格,使其顶部对齐t,然后使用\subcaptionbox相同宽度的 es 添加标题。另外,我反对使用 ,\resizebox因为它会弄乱字体,而是使用\scriptsize\small(如果合适)减小字体大小以使字体变小。

\documentclass{article}
\usepackage[margin=20mm]{geometry}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{table}[h]
    \centering
    \scriptsize
    \begin{subtable}[t]{.33\textwidth}
        \centering
        \begin{tabular}[t]{l|r}
        Koep & Abundance \\\hline
        Dfb &   167 \\
        Cfa &   150 \\
        BSk &   121 \\
        Dfc &   112 \\
        Csb &   106 \\
        Dsb &    56 \\
        Csa &    54 \\
        Dfa &    23 \\
        ET  &    17 \\
        Dsc &    15 \\
        Bwk &    15 \\
        Cfb &    14 \\
        Bwh &     5 \\
        Bsh &     4 \\
        Cfc &     4 \\
        Am  &     1 \\
        Aw  &     1 
        \end{tabular}
        \begin{tabular}[t]{l|r}
        Koep &  Abundance \\\hline
        Dfb &    34 \\
        Cfa &    31 \\
        BSk &    30 \\
        Csa &    29 \\
        Dfc &    29 \\
        Csb &    23 \\
        Dsb &    17 \\
        Dfa &    11 \\
        Cfb &     2 \\
        ET  &     2 \\
        Bsh &     2 \\
        Dwa &     2 \\
        Bwh &     1 \\
        Dsc &     1 
        \end{tabular}
    \end{subtable}\hfill
    \begin{subtable}[t]{.66\textwidth}
        \centering
        \begin{tabular}[t]{l|r}
        Land Cover & Abundance\\\hline
        Grasslands           &    355 \\
        Savannah's             &    136 \\
        Woody Savannah's         &    120 \\
        Croplands            &    104 \\
        Deciduous Brdlf Frsts   &     44 \\
        Open Shrublands       &     37 \\
        Evergreen Ndllf Frsts  &     32 \\
        Mixed Frsts          &     21 \\
        Barren               &      7 \\
        Cropland/Veg Mosaic  &      3 \\
        Urban and Built-up     &      2 \\
        Evergreen Brdlf Frsts &      2 \\
        Closed Shrublands      &      2 
        \end{tabular}
        \begin{tabular}[t]{l|r}
        Land Cover  &  Abundance \\\hline
        Grasslands           &     94 \\
        Savannah's             &     32 \\
        Croplands            &     31 \\
        Woody Savannah's          &     27 \\
        Deciduous Brdlf Frsts   &      8 \\
        Evergreen Brdlf Frsts  &      8 \\
        Open Shrublands       &      6 \\
        Mixed Frsts          &      4 \\
        Cropland/Veg Mosaic  &      2 \\
        Evergreen Brdlf Frsts &      1 \\
        Urban and Built-up     &      1 
        \end{tabular}
    \end{subtable}
    \subcaptionbox{Caption 1}[.33\textwidth]{}\hfill
    \subcaptionbox{caption 2}[.66\textwidth]{}
\caption{Caption }\label{tab:sec}
\end{table}

\end{document}

答案2

现在大部分内容都离题了,但你可能喜欢……

\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tabularray}
\UseTblrLibrary{siunitx, counter}

\begin{document}
    \begin{table}[ht]
    \footnotesize
\begin{subtable}[t]{0.33\linewidth}
\begin{talltblr}[
    label=none,     % <---
    entry=none,     % <---
                ]{baseline= t,
                  colspec = {@{} l | Q[c, si={table-format=3.0{1}}] @{}},
                  row{1} = {guard}}
    Koep & Ab.\TblrNote{1} \\
    \hline
    Dfb &   167 \\
    Cfa &   150 \\
    BSk &   121 \\
    Dfc &   112 \\
    Csb &   106 \\
    Dsb &    56 \\
    Csa &    54 \\
    Dfa &    23 \\
    ET  &    17 \\
    Dsc &    15 \\
    Bwk &    15 \\
    Cfb &    14 \\
    Bwh &     5 \\
    Bsh &     4 \\
    Cfc &     4 \\
    Am  &     1 
\end{talltblr}\quad 
\begin{talltblr}[
    label=none,     % <---
    entry=none,     % <---
note{1} = {Abundance}
                ]{baseline= t,
                  colspec = {@{} l | Q[c, si={table-format=2.0{1}}] @{}},
                   row{1} = {guard}}
    Koep & Ab.\TblrNote{1} \\
    \hline
    Aw  &     1 \\
    Dfb &    34 \\
    Cfa &    31 \\
    BSk &    30 \\
    Csa &    29 \\
    Dfc &    29 \\
    Csb &    23 \\
    Dsb &    17 \\
    Dfa &    11 \\
    Cfb &     2 \\
    ET  &     2 \\
    Bsh &     2 \\
    Dwa &     2 \\
    Bwh &     1 \\
    Dsc &     1 \\
    \hline  
\end{talltblr}
\caption{Sub caption 1}
    \end{subtable}
\hfill
\begin{subtable}[t]{0.66\linewidth}
\begin{talltblr}[
    label=none,     % <---
    entry=none,     % <---
                ]{baseline=t,
                  colspec = {@{} l | Q[c, si={table-format=3.0{1}}] @{}},
                   rowsep = 1pt,
                   row{1} = {guard}}
Land Cover & Ab.\TblrNote{1} \\
    \hline
    Grasslands              &    355 \\
    Savannah's              &    136 \\
    Woody Savannah's        &    120 \\
    Croplands               &    104 \\
    Deciduous Brdlf Frsts   &     44 \\
    Open Shrublands         &     37 \\
    Evergreen Ndllf Frsts   &     32 \\
    Mixed Frsts             &     21 \\
    Barren                  &      7 \\
    Cropland/Veg Mosaic     &      3 \\
    Urban and Built-up      &      2 \\
    Evergreen Brdlf Frsts   &      2 
\end{talltblr}\quad 
\begin{talltblr}[
    label=none,     % <---
    entry=none,     % <---
note{1} = {Abundance}
                ]{baseline=t,
                  colspec = {@{} l | Q[c, si={table-format=2.0{1}}] @{}},
                   rowsep = 1pt,
                   row{1} = {guard}}
Land Cover & Ab.\TblrNote{1}        \\
    \hline
    Closed Shrublands       &      2 \\
    Grasslands              &     94 \\
    Savannah's              &     32 \\
    Croplands               &     31 \\
    Woody Savannah's        &     27 \\
    Deciduous Brdlf Frsts   &      8 \\
    Evergreen Brdlf Frsts   &      8 \\
    Open Shrublands         &      6 \\
    Mixed Frsts             &      4 \\
    Cropland/Veg Mosaic     &      2 \\
    Evergreen Brdlf Frsts   &      1 \\
    Urban and Built-up      &      1 \\
    \hline 
\end{talltblr}
\caption{Sub caption 1}
    \end{subtable}

\caption{Common caption}
\label{tab:sec}
    \end{table}
\end{document}

在此处输入图片描述

答案3

\resizebox除非您真的不介意使表格中使用的字体大小太小而导致表格的内容几乎无法阅读,否则不要使用。

我建议您 (a) 在所有 4 个环境中将“Abundance”更改为“Abund。” tabular(以使右侧列更窄)和 (b) 允许左侧列自动换行,以使它们也更窄。将右侧列中的数字与其(隐式)小数标记对齐也不错。并且,考虑将标题放在表格的顶部而不是底部。

以下代码和相关屏幕截图给出了这些建议的应用。请注意,答案没有使用指令,\resizebox而是使用\small指令,将字体大小线性减少 10%,而是使用指令\scriptsize,将字体大小线性减少 30%。

在此处输入图片描述

\documentclass{article}  % or some other suitable document class
\usepackage{subcaption}  % for 'subtable' env.
\usepackage{array}       % for '\newcolumntype' macro
\usepackage{ragged2e}    % for '\RaggedRight' macro
\usepackage{siunitx}     % for 'S' column type
\newlength\mylen
\newcolumntype{P}[1]{% automatic linebreaking, hanging indentation
    >{\RaggedRight\hangafter=1\hangindent=1em}p{#1}}
    
\begin{document}

\begin{table}[h]
\setlength\tabcolsep{3pt} % default: 6pt
\small % for a 10% linear font size reduction
\settowidth\mylen{Open Shrublll} % found by trial and error

\caption{Caption}\label{tab:sec}

\begin{subtable}[t]{0.37\textwidth}
\caption{Caption 1}
\begin{tabular}[t]{@{} l | S[table-format=3.0] @{}}
        Koep & {Abund.} \\
        \hline
        Dfb &   167 \\
        Cfa &   150 \\
        BSk &   121 \\
        Dfc &   112 \\
        Csb &   106 \\
        Dsb &    56 \\
        Csa &    54 \\
        Dfa &    23 \\
        ET  &    17 \\
        Dsc &    15 \\
        Bwk &    15 \\
        Cfb &    14 \\
        Bwh &     5 \\
        Bsh &     4 \\
        Cfc &     4 \\
        Am  &     1 \\
        Aw  &     1 
\end{tabular}\hfill
\begin{tabular}[t]{@{} l | S[table-format=2.0] @{}}
        Koep &  {Abund.} \\
        \hline
        Dfb &    34 \\
        Cfa &    31 \\
        BSk &    30 \\
        Csa &    29 \\
        Dfc &    29 \\
        Csb &    23 \\
        Dsb &    17 \\
        Dfa &    11 \\
        Cfb &     2 \\
        ET  &     2 \\
        Bsh &     2 \\
        Dwa &     2 \\
        Bwh &     1 \\
        Dsc &     1 
\end{tabular}
\end{subtable}\hfill
\begin{subtable}[t]{0.58\textwidth}
\caption{Caption 2}
\begin{tabular}[t]{@{} P{\mylen} | S[table-format=3.0] @{}}
        Land Cover & {Abund.}\\
        \hline
        Grasslands           &    355 \\
        Savannahs            &    136 \\
        Woody Savannahs      &    120 \\
        Croplands            &    104 \\
        Deciduous Brdlf Frsts&     44 \\
        Open Shrublands      &     37 \\
        Evergreen Ndllf Frsts&     32 \\
        Mixed Frsts          &     21 \\
        Barren               &      7 \\
        Cropland\slash Veg Mosaic & 3 \\
        Urban and Built-up   &      2 \\
        Evergreen Brdlf Frsts&      2 \\
        Closed Shrublands    &      2 
\end{tabular}\hfill
\begin{tabular}[t]{@{} P{\mylen} | S[table-format=2.0] @{}}
        Land Cover  &  {Abund.} \\
        \hline
        Grasslands           &     94 \\
        Savannahs            &     32 \\
        Croplands            &     31 \\
        Woody Savannahs      &     27 \\
        Deciduous Brdlf Frsts&      8 \\
        Evergreen Brdlf Frsts&      8 \\
        Open Shrublands      &      6 \\
        Mixed Frsts          &      4 \\
        Cropland\slash Veg Mosaic & 2 \\
        Evergreen Brdlf Frsts&      1 \\
        Urban and Built-up   &      1 
\end{tabular}
\end{subtable}
\end{table}

\end{document}

附录:将上面给出的解决方案与这个答案,它不会尝试减小列宽。文本宽度相同,我通过减少\tabcolsep和消除环境左侧和右侧边缘的空白填充来帮助替代解决方案tabular。我的解决方案使用\small,而另一个使用\tiny(字体大小线性减少 50%)。我想可以说,可读性存在巨大差异。

在此处输入图片描述

相关内容