将表格垂直居中在子浮动内

将表格垂直居中在子浮动内

以下 MWE 并排生成两个表格:

\documentclass{report}

\usepackage{tabu}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{subfig}
\usepackage{siunitx}
\usepackage[version=3]{mhchem}

\newcommand{\ul}{\si{\micro\liter}}
\newcommand{\uM}{\si{\micro}M}
\newcommand{\degc}{\si{\celsius}}

\begin{document}

\begin{table}[h]
        \centering
        \caption{PCR conditions}

        \subfloat{\begin{tabu}{lrrrr}
            \toprule
                            & 1X        & 2X        & Total     & Per tube  \\
            \midrule
            \ce{H2O}        & 9.10 \ul  & 18.20 \ul & 18.20 \ul & 9.10 \ul  \\
            2X KAPA HiFi    & 10.00 \ul & 20.00 \ul & 38.20 \ul & 19.10 \ul \\
            AMPG1 (10 \uM ) & 0.40 \ul  & 0.80 \ul  & 39.00 \ul & 19.50 \ul \\
            ORIG1 (10 \uM ) & 0.40 \ul  & 0.80 \ul  & 39.80 \ul & 19.90 \ul \\
            Template        & 0.25 \ul  & ---       & ---       & ---       \\
            \midrule
            \textbf{Total}  & 20.00 \ul & ---       & ---       & ---       \\
            \bottomrule
        \end{tabu}}
        \subfloat{
            \begin{tabu}{ccc}
                \toprule
                \multicolumn{2}{c}{95\degc}     & 3:00      \\
                \midrule
                \multirow{3}{*}{x35} & 98\degc  & 0:30      \\
                                     & 54\degc  & 0:20      \\
                                     & 72\degc  & 1:00      \\
                \midrule
                \multicolumn{2}{c}{72\degc}     & 3:00      \\
                \multicolumn{2}{c}{4\degc}      & $\infty$  \\
                \bottomrule
            \end{tabu}
        }
\end{table}

\end{document}

然而,第二张表的位置很尴尬:

在此处输入图片描述

我希望将第二张较小的表格向下移动,以便它位于较大的第一张表格的中心。

答案1

由于您没有为\subfloats 使用任何标题,因此您应该将其删除;表格默认是垂直居中的:

在此处输入图片描述

\documentclass{report}
\usepackage[margin=1in]{geometry}% Just for this example

\usepackage{tabu,booktabs,multirow,siunitx}
\usepackage[version=3]{mhchem}

\newcommand{\ul}{\si{\micro\liter}}
\newcommand{\uM}{\si{\micro}M}
\newcommand{\degc}{\si{\celsius}}

\begin{document}

\begin{table}[h]
  \centering
  \caption{PCR conditions}

  \begin{tabu}{lrrrr}
    \toprule
                    & 1X        & 2X        & Total     & Per tube  \\
    \midrule
    \ce{H2O}        & 9.10 \ul  & 18.20 \ul & 18.20 \ul & 9.10 \ul  \\
    2X KAPA HiFi    & 10.00 \ul & 20.00 \ul & 38.20 \ul & 19.10 \ul \\
    AMPG1 (10 \uM ) & 0.40 \ul  & 0.80 \ul  & 39.00 \ul & 19.50 \ul \\
    ORIG1 (10 \uM ) & 0.40 \ul  & 0.80 \ul  & 39.80 \ul & 19.90 \ul \\
    Template        & 0.25 \ul  & ---       & ---       & ---       \\
    \midrule
    \textbf{Total}  & 20.00 \ul & ---       & ---       & ---       \\
    \bottomrule
  \end{tabu}
  \begin{tabu}{ccc}
    \toprule
    \multicolumn{2}{c}{95\degc}     & 3:00      \\
    \midrule
    \multirow{3}{*}{x35} & 98\degc  & 0:30      \\
                         & 54\degc  & 0:20      \\
                         & 72\degc  & 1:00      \\
    \midrule
    \multicolumn{2}{c}{72\degc}     & 3:00      \\
    \multicolumn{2}{c}{4\degc}      & $\infty$  \\
    \bottomrule
  \end{tabu}
\end{table}

\end{document}

答案2

如果您确实想使用\subfloat,并且由于它会自动对齐顶部,您必须谎报禁忌的大小。另一方面,基线已经垂直居中。

\documentclass{report}

\usepackage{tabu}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{subfig}
\usepackage{siunitx}
\usepackage[version=3]{mhchem}

\newcommand{\ul}{\si{\micro\liter}}
\newcommand{\uM}{\si{\micro}M}
\newcommand{\degc}{\si{\celsius}}

% used to compute height of larger tabu
\newsavebox{\boxA}
\newlength{\lenA}

% not really needed after all
\newsavebox{\boxB}
\newlength{\lenB}

\begin{document}

\savebox{\boxA}{
  \begin{tabu}{lrrrr}
     \toprule
                     & 1X        & 2X        & Total     & Per tube  \\
     \midrule
     \ce{H2O}        & 9.10 \ul  & 18.20 \ul & 18.20 \ul & 9.10 \ul  \\
     2X KAPA HiFi    & 10.00 \ul & 20.00 \ul & 38.20 \ul & 19.10 \ul \\
     AMPG1 (10 \uM ) & 0.40 \ul  & 0.80 \ul  & 39.00 \ul & 19.50 \ul \\
     ORIG1 (10 \uM ) & 0.40 \ul  & 0.80 \ul  & 39.80 \ul & 19.90 \ul \\
     Template        & 0.25 \ul  & ---       & ---       & ---       \\
     \midrule
     \textbf{Total}  & 20.00 \ul & ---       & ---       & ---       \\
     \bottomrule
  \end{tabu}
}
\settoheight{\lenA}{\usebox{\boxA}}% distance from top to baseline

\savebox{\boxB}{
     \begin{tabu}{ccc}
        \toprule
        \multicolumn{2}{c}{95\degc}     & 3:00      \\
        \midrule
        \multirow{3}{*}{x35} & 98\degc  & 0:30      \\
                             & 54\degc  & 0:20      \\
                             & 72\degc  & 1:00      \\
        \midrule
        \multicolumn{2}{c}{72\degc}     & 3:00      \\
        \multicolumn{2}{c}{4\degc}      & $\infty$  \\
        \bottomrule
      \end{tabu}
}
\settoheight{\lenB}{\usebox{\boxB}}

\begin{table}[h]
        \centering
        \caption{PCR conditions}
        \subfloat{\usebox{\boxA}}
        \subfloat{\raisebox{0pt}[\lenA]{\usebox{\boxB}}}
\end{table}

\end{document}

注意:任何\raisebox参数组合都可以起作用,例如基线降低的距离和从顶部到基线的(假)距离之和\lenA

禁忌

答案3

这是一个解决方案,其中单位移到数字之上,并\uM定义了新的宏。我认为这既澄清了代码,也澄清了符号。

\documentclass{report}

\usepackage{booktabs}
\usepackage{subfig}
\usepackage{siunitx}
\usepackage[version = 4]{mhchem}

\DeclareSIUnit\molar{M}
\DeclareSIUnit\uM{\micro\molar}

\newsavebox{\boxA}
\newlength{\lenA}
\newsavebox{\boxB}
\newlength{\lenB}


\begin{document}

\savebox{\boxA}{
  \begin{tabular}{l *{4}{S[table-format = 2.2]}}
   \toprule
                         & {1X}       & {2X}       & {Total}    & {Per tube} \\
                         & {\si{\uL}} & {\si{\uL}} & {\si{\uL}} & {\si{\uL}} \\
   \midrule
    \ce{H2O}             &  9.10      & 18.20      & 18.20      &  9.10      \\
    2X KAPA HiFi         & 10.00      & 20.00      & 38.20      & 19.10      \\
    AMPG1 (\SI{10}{\uM}) &  0.40      &  0.80      & 39.00      & 19.50      \\
    ORIG1 (\SI{10}{\uM}) &  0.40      &  0.80      & 39.80      & 19.90      \\
    Template             &  0.25      & {---}      & {---}      & {---}      \\
   \midrule
    \textbf{Total}       & 20.00      & {---}      & {---}      & {---}      \\
   \bottomrule
 \end{tabular}
}
\settoheight{\lenA}{\usebox{\boxA}}

\savebox{\boxB}{
  \begin{tabular}{c S[table-format = 2] c}
   \toprule
    ---         & {\si{\celsius}} & ---      \\
   \midrule
                & 95              & 3:00     \\
    $\times 35$ & 98              & 0:30     \\
                & 54              & 0:20     \\
                & 72              & 1:00     \\
   \midrule
                & 72              & 3:00     \\
                &  4              & $\infty$ \\
   \bottomrule
  \end{tabular}
}
\settoheight{\lenB}{\usebox{\boxB}}

\begin{table}
 \centering
 \caption{PCR conditions.}
  \subfloat{\usebox{\boxA}}
  \subfloat{\raisebox{0pt}[\lenA]{\usebox{\boxB}}}
\end{table}

\end{document}

输出

相关内容