在 beamer 中对齐表格和三部分表格时摆脱魔法数字

在 beamer 中对齐表格和三部分表格时摆脱魔法数字

我一直在尝试制作常规表格并threeparttables在投影仪中排队为了 A 尽管 现在。我一直在取得进展:在下面的 MWE 中,表格排列得很完美。但仍然有一个神奇数字我一直无法摆脱烦人的4.30003pt,不幸的是,它需要随文档字体大小而改变。你能帮我找出它的来源吗?是否有一些保存的长度保存着我可以使用它的值,而不是仅仅硬连线它。在日志文件中,4.30003pt显示在标题下Completed box being shipped out [1]--- 即带有常规框架的框架 --- 上......\glue(\baselineskip) 4.30003,不幸的是,我无法破译 :(

\documentclass[10pt, t]{beamer}
\makeatletter
\renewenvironment{table}[1][]{%Redefine table environment as per https://tex.stackexchange.com/a/603004/71332
  \def\@captype{table}%
  \par\nobreak\centering\vspace{0.45\baselineskip}}
  {\par\nobreak}
\makeatother
\usepackage[singlelinecheck=false,
            position=above]{caption}% Format captions for figures and tables
\newlength{\generalcaptionskip}
\setlength{\generalcaptionskip}{\dimexpr\abovecaptionskip-\parskip\relax}
\newlength{\TPTcaptionskip}
\setlength{\TPTcaptionskip}{\abovecaptionskip}
\captionsetup{skip=\generalcaptionskip}
\captionsetup[threeparttable]{skip=\TPTcaptionskip}
\newlength{\TPTpreskip}
\setlength{\TPTpreskip}{\dimexpr-\parskip-\baselineskip+4.30003pt\relax}
\AtBeginEnvironment{threeparttable}{\vspace{\TPTpreskip}}%Move threeparttables up to align with regular tables
\usepackage{booktabs,tabularx}
\usepackage[para, flushleft]{threeparttable}
\showoutput
\begin{document}
  \begin{frame}{table}
    \begin{table}
      \caption{A table}
      \begin{tabularx}{\linewidth}{@{} Xrrrrr @{}}
        \toprule
        & A & B & C & D & E \tabularnewline
        \midrule
        A somewhat longish row heading & 12 & 34 & 56 & 78 & 90 \tabularnewline
        \bottomrule
      \end{tabularx}
    \end{table}
  \end{frame}
  \begin{frame}{threeparttable}
    \begin{table}
      \begin{threeparttable}
        \caption{A table}
        \begin{tabularx}{\linewidth}{@{} Xrrrrr @{}}
          \toprule
          & A & B & C & D & E \tabularnewline
          \midrule
          A somewhat longish row heading & 12 & 34 & 56 & 78 & 90 \tabularnewline
          \bottomrule
        \end{tabularx}
        \begin{tablenotes}
          \emph{Note:} Something noteworthy.
        \end{tablenotes}
      \end{threeparttable}
    \end{table}
  \end{frame}
\end{document}

答案1

使用我的新 LaTeX3 包的替代解决方案tabularray

\documentclass[10pt,t]{beamer}

\usepackage[singlelinecheck=false,
            position=above]{caption}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\SetTblrTemplate{head}{empty}
\SetTblrTemplate{note}{inline}
\SetTblrOuter[talltblr]{headsep=0pt}

\begin{document}
  \begin{frame}{short table}
    \begin{table}
      \caption{A table}
      \begin{tblr}{@{}Xrrrrr@{}}
        \toprule
        & A & B & C & D & E \\
        \midrule
        A somewhat longish row heading & 12 & 34 & 56 & 78 & 90 \\
        \bottomrule
      \end{tblr}
    \end{table}
  \end{frame}
  \begin{frame}{tall table}
    \begin{table}
      \caption{A table}
      \begin{talltblr}[
        note{a} = {First Footnote.},
        note{b} = {Second Footnote.},
        remark{Note} = {Something noteworthy.},
      ]{@{}Xrrrrr@{}}
        \toprule
        & A\TblrNote{a} & B & C & D & E \\
        \midrule
        A somewhat longish row heading\TblrNote{b} & 12 & 34 & 56 & 78 & 90 \\
        \bottomrule
      \end{talltblr}
    \end{table}
  \end{frame}
\end{document}

在此处输入图片描述

相关内容