表格对齐(3 个表格)

表格对齐(3 个表格)

我有三个并排的桌子,我想将它们的水平线对齐到同一水平。我该怎么做?

在此处输入图片描述

这是我的 LaTeX 背面代码:

\begin{table}
\centering
        \footnotesize
            \begin{tabular}[t]{p{2.5cm}c c}
            \multicolumn{2}{c}{\textbf{Group A}}\\
                \toprule
                Agitator speed (rpm) & $U\ (\frac{BTU}{hr\ ft^2\ ^\circ F})$\\
                &\\
                \midrule
                680 & 9.374 $\pm0.002$\\
                950 & 10.140 $\pm0.004$\\
                1500 & 10.575 $\pm0.002$\\
                \bottomrule
            \end{tabular}
            \hfill
            \begin{tabular}[t]{p{1.7cm}c c}
            \multicolumn{2}{c}{\textbf{Group C}}\\
                \toprule
                P (PSIG) & $U\ (\frac{BTU}{hr\ ft^2\ ^\circ F})$\\
                &\\
                &\\
                \midrule
                15 & 104.1 $\pm0.1$\\
                30 & 111.6 $\pm0.1$\\
                &\\
                \bottomrule
            \end{tabular}
            \hfill
            \begin{tabular}[t]{p{1.7cm}c c}
            \multicolumn{2}{c}{\textbf{Group D}}\\
                \toprule
                $\dot{V}$ ($\frac{m^3}{s}$)                                 & $U\ (\frac{BTU}{hr\ ft^2\ ^\circ F})$ \\
                &\\
                &\\
                \midrule
                $2.05 \cdot 10^{-4}$ & 1616\\
                $3.79 \cdot 10^{-4}$ & 3138\\  
                &\\
                \bottomrule
            \end{tabular}
        \end{table}

答案1

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tabularray}
\begin{document}
\begin{table}
\centering
\begin{tblr}
{
colspec        = {X[c,m]X[c,m]X[c,m]X[c,m]X[c,m]X[c,m]},
cell{1}{1,3,5} = {c=2}{},
row{1}         = {font=\bfseries},
hline{2,Z}     = {1-2}{wd=.08em,leftpos=-1,rightpos=-1,endpos=true},
hline{2,Z}     = {3-4}{wd=.08em,leftpos=-1,rightpos=-1,endpos=true},
hline{2,Z}     = {5-6}{wd=.08em,leftpos=-1,rightpos=-1,endpos=true},
hline{3}       = {1-2}{wd=.05em,leftpos=-1,rightpos=-1,endpos=true},
hline{3}       = {3-4}{wd=.05em,leftpos=-1,rightpos=-1,endpos=true},
hline{3}       = {5-6}{wd=.05em,leftpos=-1,rightpos=-1,endpos=true},
}
Group A              &                                       & Group C  &                                       & Group D                     &                                       \\
Agitator speed (rpm) & $U\ (\frac{BTU}{hr\ ft^2\ ^\circ F})$ & P (PSIG) & $U\ (\frac{BTU}{hr\ ft^2\ ^\circ F})$ & $\dot{V}$ ($\frac{m^3}{s}$) & $U\ (\frac{BTU}{hr\ ft^2\ ^\circ F})$ \\
680                  & 9.374 $\pm~0.002$                     & 15       & 104.1 $\pm~0.1$                       & $2.05 \cdot 10^{-4}$        & 1616                                  \\
950                  & 10.140 $\pm~0.004$                    & 30       & 111.6 $\pm~0.1$                       & $3.79 \cdot 10^{-4}$        & 3138                                  \\
1500                 & 10.575 $\pm~0.002$                    &          &                                       &                             &                                       \\
\end{tblr}
\end{table}
\end{document}

在此处输入图片描述

答案2

以下代码对我有用。我在下面列出了我所做的更改。

  1. \renewcommand\arraystretch{1.5} \setlength\minrowclearance{1.5pt}在序言中添加了 colortbl 包和命令来固定行高。
  2. 将 (rpm) 文本移至第二行,而不是将其保留在第一行。
  3. 删除了第二和第三个表格中中间规则之前的其中一个空行。这是为了确保所有表格的行数相同。
\documentclass[letter,10pt]{article}
\usepackage{booktabs} %for toprule, midrule and bottomrule
\usepackage{colortbl} %for minirowclearance

%fix row height for all tables
\renewcommand\arraystretch{1.5} 
\setlength\minrowclearance{1.5pt}


\begin{document}



\begin{table}
\centering
        \footnotesize
            \begin{tabular}[t]{p{2.5cm}c c}
            \multicolumn{2}{c}{\textbf{Group A}}\\
                \toprule
                Agitator speed  & $U\ (\frac{BTU}{hr\ ft^2\ ^\circ F})$\\
                (rpm)&&\\

                \midrule
                680 & 9.374 $\pm0.002$\\
                950 & 10.140 $\pm0.004$\\
                1500 & 10.575 $\pm0.002$\\
                \bottomrule
            \end{tabular}
            \hfill
            \begin{tabular}[t]{p{1.7cm}c c}
            \multicolumn{2}{c}{\textbf{Group C}}\\
                \toprule
                P (PSIG) & $U\ (\frac{BTU}{hr\ ft^2\ ^\circ F})$\\
                &\\

                \midrule
                15 & 104.1 $\pm0.1$\\
                30 & 111.6 $\pm0.1$\\
                &\\
                \bottomrule
            \end{tabular}
            \hfill
            \begin{tabular}[t]{p{1.7cm}c c}
            \multicolumn{2}{c}{\textbf{Group D}}\\
                \toprule
                $\dot{V}$ ($\frac{m^3}{s}$) & $U\ (\frac{BTU}{hr\ ft^2\ ^\circ F})$ \\
                &\\

                \midrule
                $2.05 \cdot 10^{-4}$ & 1616\\
                $3.79 \cdot 10^{-4}$ & 3138\\  
                &\\
                \bottomrule
            \end{tabular}
        \end{table}
\end{document}

答案3

经过近两年的时间......

我将通过以下方式解决您的问题:

  • 将所有树表合并为一张表。
  • 用于表格规则\cmidrule
  • 为了缩短U列中的代码,定义新的 SI 单位
  • 为了缩短不确定性的写作时间,利用siunitx包的功能

梅威瑟:

\documentclass{article}
\usepackage{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}


\begin{document}
    \begin{table}
    \DeclareSIUnit\U{hr\,ft^2\,^{\circ}F}
    \sisetup{uncertainty-mode = separate}
    \centering    
\begin{tblr}{colspec = {Q[c, si={table-format=4.0}]   Q[c, si={table-format=2.4(3)}]
                        Q[c, si={table-format=3.3}]   Q[c, si={table-format=3.2(1)}]
                        Q[c, si={table-format=1.2e2}] Q[c, si={table-format=4.0}]
                        },
             row{1}  = {font=\bfseries},
             row{1,2}= {guard},
             }
\SetCell[c=2]{c} Group A
        &   & \SetCell[c=2]{c} Group B
                    &   & \SetCell[c=2]{c} Group C                   
                                    &       \\
    \cmidrule[lr,\heavyrulewidth]{1-2}
    \cmidrule[lr,\heavyrulewidth]{3-4}
    \cmidrule[lr,\heavyrulewidth]{5-6}
{Agitator speed\\ (rpm)} 
        & {$U$\\ $\left(\frac{BTU}{\unit{\U}}\right)$} 
            & {P\\ (PSIG)} 
                    & {$U$\\ $\left(\frac{BTU}{\unit{\U}}\right)$}
                        & {$\dot{V}$\\ (rpm)}
                                    & {$\left(\frac{BTU}{\unit{\U}}\right)$}
                                            \\
    \cmidrule[lr]{1-2}
    \cmidrule[lr]{3-4}
    \cmidrule[lr]{5-6}
 680    &   9.374(2) 
            & 15    & 104.1(1)
                        & 2.05e-4   & 1616  \\
 950    & 10.140(4) 
            & 30    & 111.6(1)
                        & 3.79e-4   & 3138  \\
1500    & 10.575(2) 
            &       &   &           &       \\
    \cmidrule[lr,\heavyrulewidth]{1-2}
    \cmidrule[lr,\heavyrulewidth]{3-4}
    \cmidrule[lr,\heavyrulewidth]{5-6}
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

(红线表示文本块边框)

答案4

如果你喜欢复杂一点的,你可以这样做\vphantom

\documentclass{article}
%\errorcontextlines=10000

\ExplSyntaxOn
%----------------------------------------------------------------------------
% A dumb copy of \int_step_function:nN where instead of a single function you
% can supply several tokens where the number is appended to

\cs_new:Npn \int_step_AppendToTokens:nn {\int_step_ToTokens:nnnn {1}{1}}

\cs_new:Npn \int_step_ToTokens:nnnn #1#2#3 { \exp_after:wN \__int_step:wwwn
\int_value:w \__int_eval:w #1\exp_after:wN ;\int_value:w \__int_eval:w
#2\exp_after:wN ;\int_value:w \__int_eval:w #3; }

\cs_new:Npn \__int_step:wwwn #1;#2;#3;#4 { \int_compare:nNnTF
{#2}>\c_zero_int {\__int_step:Nwnnn >}{\int_compare:nNnTF {#2}=\c_zero_int
{\__kernel_msg_expandable_error:nnn {kernel}{zero-step}{#4}\prg_break:
}{\__int_step:Nwnnn <}}#1;{#2}{#3}{#4}\prg_break_point: }

\cs_new:Npn \__int_step:Nwnnn #1#2;#3#4#5 { \if_int_compare:w
#2#1#4\exp_stop_f: \prg_break:n \fi: #5{#2}\exp_after:wN \__int_step:Nwnnn
\exp_after:wN #1\int_value:w \__int_eval:w #2+#3;{#3}{#4}{#5} }
%----------------------------------------------------------------------------
\cs_new:Npn \vphantoms #1#2 {
  \int_step_AppendToTokens:nn {\tl_count:n {#1}} {\dovphantom:nn{#1}}
  \tl_item:nn {#1} {#2}
}
\cs_new:Nn \dovphantom:nn {\vphantom{\tl_item:nn {#1} {#2}}}
\ExplSyntaxOff
\newlength\scratchylength

\usepackage{booktabs, amsmath}

\begin{document}

\begin{table}
  \centering
  \footnotesize
  \noindent
  \def\phantomtable#1#2{%
    \begin{tabular}[t]{lr}
        \multicolumn{2}{c}{\textbf{%
          \vphantoms{{Group A}{Group C}{Group D}}{#1}%
        }}%
      \\
      \toprule
        \vphantoms{%
          {\settowidth\scratchylength{Agitator}%
           \parbox[t]{\scratchylength}{%
             Agitator speed%
             % Do a \hfill at the begin of the new line if line is broken here:
             \nobreak\penalty 50 \space\hskip 0pt plus -1fill\relax\hbox{}\nobreak\hfill
             (rpm)%
           }%
          }%
          {\settowidth\scratchylength{P (PSIG)}%
           \parbox[t]{\scratchylength}{P (PSIG)}}%
          {\settowidth\scratchylength{$\dot{V}$ ($\frac{\text{m}^3}{\text{s}}$)}%
           \parbox[t]{\scratchylength}{$\dot{V}$ ($\frac{\text{m}^3}{\text{s}}$)}}%
        }{#1}%
      &%
        $U$ $\left(\frac{BTU}{\text{hr\,$\text{ft}^2$\,$^{\circ}$F}}\right)$%
      \\
      \midrule
        \vphantoms{{680}{15}{$2.05 \cdot 10^{-4}$}}{#1}%
      &%
        \vphantoms{{9.374 $\pm0.002$}{104.1 $\pm0.1$}{1616}}{#1}%
      \\%
        \vphantoms{{950}{30}{$3.79 \cdot 10^{-4}$}}{#1}%
      &%
        \vphantoms{{10.140 $\pm0.004$}{111.6 $\pm0.1$}{3138}}{#1}%
      \\%
        \vphantoms{{1500}{}{}}{#1}&\vphantoms{{10.575 $\pm0.002$}{}{}}{#1}%
      \\%
      \bottomrule
    \end{tabular}%
    #2%
  }%
  \phantomtable{1}{\nobreak\hskip .75em plus 1 fill}%
  \phantomtable{2}{\nobreak\hskip .75em plus 1 fill}%
  \phantomtable{3}{}%
\end{table}

\end{document}

在此处输入图片描述

相关内容