将两个不平整的表格的 \bottomrule 设置为相同高度

将两个不平整的表格的 \bottomrule 设置为相同高度

我有两个高度不等的平行桌子。我想将\bottomrule较矮的左侧桌子设置为与右侧桌子相同的高度。如果不重新排列行,这是否可行?使用\vspace{}是我尝试过的一种方法,但太棘手了。所以我问自己是否有更好的解决方案?

\documentclass{article}

\usepackage{ragged2e, tabularx, makecell, booktabs}

\newcommand\mc[1]{%
    \multicolumn{1}{c}{#1}}

\renewcommand\tabularxcolumn[1]{%
    >{\RaggedRight}m{#1}}

\begin{document}

\begin{table}[!htb]\centering\small\setlength{\extrarowheight}{2pt}
    \caption{Two uneven parallel tables.\label{tab:test}}
    \begin{tabularx}{.45\columnwidth}[t]{XX}
        \toprule
            \mc{Column1} & \mc{Column2} \\
        \midrule
            Row 1 & Row 1 \\
            Row 2 & Row 2 \\
            Row 3 & Row 3 \\
            Row 4 & Row 4 \\% \vspace{3.05pt} \\
        \bottomrule
    \end{tabularx}
    \begin{tabularx}{.45\columnwidth}[t]{XX}
        \toprule
           \mc{Column1} & \mc{Column2} \\
        \midrule
            Row 1 & \makecell[l]{Row 1 with \\ line break} \\
            Row 2 & Row 2 \\
            \makecell[l]{Row 2 with \\ line break} & Row 2 \\
        \bottomrule
    \end{tabularx}
\end{table}

\end{document}

答案1

您可以\hbox将两个表合并,然后将它们显示在两个表中,将另一个表的内容添加为 ,\vphantom并在其下方添加\bottomrule。请注意,您不应\bottomrule在两个表中使用,它是自动添加的。

\documentclass{article}

\usepackage{ragged2e, tabularx, makecell, booktabs}

\newcommand\mc[1]{%
    \multicolumn{1}{c}{#1}}

\renewcommand\tabularxcolumn[1]{%
    >{\RaggedRight}m{#1}}

\newsavebox\resizeboxA
\newsavebox\resizeboxB
\newcommand\BottomRuleAligned
  {%
    \begingroup
    \def\additionalspace{\noalign{\vfill}}%
    \setbox\resizeboxA\hbox\bgroup
      \ignorespaces
  }
\newcommand\EndFirstTable
  {%
      \ifhmode\unskip\fi
    \egroup
    \setbox\resizeboxB\hbox\bgroup
      \ignorespaces
  }
\newcommand\EndSecondTable
  {%
      \ifhmode\unskip\fi
    \egroup
    \begin{tabular}[t]{@{}l@{}}
      \vphantom{\usebox\resizeboxB}\usebox\resizeboxA\\
      \bottomrule
    \end{tabular}%
    \BottomRuleAlignedTableSep
    \begin{tabular}[t]{@{}l@{}}
      \vphantom{\usebox\resizeboxA}\usebox\resizeboxB\\
      \bottomrule
    \end{tabular}%
    \endgroup
  }
\newcommand\BottomRuleAlignedTableSep{\hskip1em}


\begin{document}

\begin{table}[!htb]\centering\small\setlength{\extrarowheight}{2pt}
    \caption{Two uneven parallel tables.\label{tab:test}}
    \BottomRuleAligned
      \begin{tabularx}{.45\columnwidth}[t]{XX}
          \toprule
              \mc{Column1} & \mc{Column2} \\
          \midrule
              Row 1 & Row 1 \\
              Row 2 & Row 2 \\
              Row 3 & Row 3 \\
              Row 4 & Row 4 \\% \vspace{3.05pt} \\
      \end{tabularx}
    \EndFirstTable
      \begin{tabularx}{.45\columnwidth}[t]{XX}
          \toprule
             \mc{Column1} & \mc{Column2} \\
          \midrule
              Row 1 & \makecell[l]{Row 1 with \\ line break} \\
              Row 2 & Row 2 \\
              \makecell[l]{Row 2 with \\ line break} & Row 2 \\
      \end{tabularx}
    \EndSecondTable
\end{table}

\end{document}

在此处输入图片描述

编辑:与单个表格上方的垂直间距相同\begin{tabularx},水平间距减少为仅一个空格。现在您不应该使用\toprule和,\bottomrule因为两者都是自动添加的(这解决了您的间距差异):

\documentclass{article}

\usepackage{ragged2e, tabularx, makecell, booktabs}

\newcommand\mc[1]{%
    \multicolumn{1}{c}{#1}}

\renewcommand\tabularxcolumn[1]{%
    >{\RaggedRight}m{#1}}

\newsavebox\resizeboxA
\newsavebox\resizeboxB
\newcommand\BottomRuleAligned
  {%
    \begingroup
    \def\additionalspace{\noalign{\vfill}}%
    \setbox\resizeboxA\hbox\bgroup
      \ignorespaces
  }
\newcommand\EndFirstTable
  {%
      \ifhmode\unskip\fi
    \egroup
    \setbox\resizeboxB\hbox\bgroup
      \ignorespaces
  }
\newcommand\EndSecondTable
  {%
      \ifhmode\unskip\fi
    \egroup
    \begin{tabular}[t]{@{}l@{}}
      \toprule
      \vphantom{\usebox\resizeboxB}\usebox\resizeboxA\\
      \bottomrule
    \end{tabular}%
    \BottomRuleAlignedTableSep
    \begin{tabular}[t]{@{}l@{}}
      \toprule
      \vphantom{\usebox\resizeboxA}\usebox\resizeboxB\\
      \bottomrule
    \end{tabular}%
    \endgroup
  }
\newcommand\BottomRuleAlignedTableSep{\space}


\begin{document}

\begin{table}[!htb]\centering\small\setlength{\extrarowheight}{2pt}
    \caption{Two uneven parallel tables.\label{tab:test}}
    \BottomRuleAligned
      \begin{tabularx}{.45\columnwidth}[t]{XX}
              \mc{Column1} & \mc{Column2} \\
          \midrule
              Row 1 & Row 1 \\
              Row 2 & Row 2 \\
              Row 3 & Row 3 \\
              Row 4 & Row 4 \\% \vspace{3.05pt} \\
      \end{tabularx}
    \EndFirstTable
      \begin{tabularx}{.45\columnwidth}[t]{XX}
             \mc{Column1} & \mc{Column2} \\
          \midrule
              Row 1 & \makecell[l]{Row 1 with \\ line break} \\
              Row 2 & Row 2 \\
              \makecell[l]{Row 2 with \\ line break} & Row 2 \\
      \end{tabularx}
    \EndSecondTable
\end{table}

\end{document}

在此处输入图片描述

答案2

由于您加载了,我们可以为列标题和其余表格makecell设置不同的值,因此这里有一个解决方案:\arraystretch\arraystretch

\documentclass{article}

\usepackage{ragged2e, tabularx, makecell, booktabs}
\usepackage{setspace}

\renewcommand\tabularxcolumn[1]{>{\RaggedRight}m{#1}}

\begin{document}

\begin{table}[!htb]\centering\small\setlength{\extrarowheight}{2pt}
\renewcommand{\theadfont}{\normalsize}
\renewcommand{\theadset}{\renewcommand{\arraystretch}{0.3}}%{\setstretch{0.3}}%
    \caption{Two uneven parallel tables.\label{tab:test}}
   \begingroup\renewcommand{\arraystretch}{1.097}
   \begin{tabularx}{.45\columnwidth}[t]{XX}
\toprule
\thead{Column 1} & \thead{Column 2} \\[-1pt]
\midrule
            Row 1 & Row 1 \\
            Row 2 & Row 2 \\
            Row 3 & Row 3 \\
            Row 4 & Row 4 \\% \vspace{3.05pt} \\
        \bottomrule
    \end{tabularx} \endgroup
    \begin{tabularx}{.45\columnwidth}[t]{XX}
\toprule
\thead{Column 1} & \thead{Column 2} \\
\midrule
            Row 1 & \makecell[l]{Row 1 with \\ line break} \\
            Row 2 & Row 2 \\
            \makecell[l]{Row 2 with \\ line break} & Row 2 \\
        \bottomrule
    \end{tabularx}
\end{table}

\end{document} 

在此处输入图片描述

相关内容