如何使用自定义 tablenotes 环境来确保 tabular 和 tabularx 的间距统一?

如何使用自定义 tablenotes 环境来确保 tabular 和 tabularx 的间距统一?

编辑稍微简单一点的例子。我可以去掉booktabs并避免\tnote,但仍然会遇到问题。我也可以改threeparttablex回默认threeparttablethreeparttable不过,去掉可以消除问题,所以我在新版本中保留了threeparttable和。enumitem


我使用threeparttable和以及使用 和 创建的表格的threeparttablex自定义环境。我的自定义环境的一个特点是它在 中设置注释。另一个特点是它不需要我手动对注释进行编号。(也就是说,注释会自动编号,并且符合的意义。)tablenotestabulartabularx\footnotesizereferablethreeparttablex

但是,我不知道如何在tabular/tabularx和之间获得均匀的垂直间距tablenotes

我使用enumitem创建自定义tablenotes环境,我可以放置before={\footnotesize},例如,作为字体。如果我这样做,间距对于tabulars 来说似乎是正确的,但对于 s 来说则完全错误tabularx

如果我使用before={\unskip\medskip\footnotesize}或更改topsep\medskipamount,间距似乎对tabularxs 来说是正确的,但实际上对 s 来说不正确tabular。更重要的是,额外的空间被添加到两个都情况下,因此tabulars 和tabularxs 在相关方面仍然看起来不一样。

无论如何,我都没有得到制服印刷一致性所要求的间距。

如何确保一致性,同时保持较小的字体大小?(我也想保留自动编号,但据我所知,这与这里并不相关。)

3 次尝试 x 2 例 = 6 个结果

\documentclass{article}
\usepackage{tabularx}
\usepackage{threeparttable}
\usepackage{enumitem}
\makeatletter
\renewlist{tablenotes}{enumerate}{1}
\setlist[tablenotes]{label=\textsuperscript{\alph*},ref=\alph*,itemsep=\z@,topsep=\z@skip,partopsep=\z@skip,parsep=\z@,itemindent=\z@,labelindent=\tabcolsep,labelsep=.2em,leftmargin=*,align=left,before={\footnotesize}}
\makeatother
\parindent=0pt
\begin{document}
\begin{table}
  \begin{threeparttable}
    \caption{Initial Attempt: Case 1}
    \begin{tabularx}\linewidth{Xl}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabularx}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\begin{table}
  \begin{threeparttable}
    \caption{Initial Attempt: Case 2}
    \begin{tabular}{ll}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabular}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\makeatletter

\setlist[tablenotes]{label=\textsuperscript{\alph*},ref=\alph*,itemsep=\z@,topsep=\z@skip,partopsep=\z@skip,parsep=\z@,itemindent=\z@,labelindent=\tabcolsep,labelsep=.2em,leftmargin=*,align=left,before={\unskip\medskip\footnotesize}}

\makeatother

\begin{table}
  \begin{threeparttable}
    \caption{Second Attempt: Case 1}
    \begin{tabularx}\linewidth{Xl}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabularx}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\begin{table}
  \begin{threeparttable}
    \caption{Second Attempt: Case 2}
    \begin{tabular}{ll}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabular}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\makeatletter

\setlist[tablenotes]{%
  label=\textsuperscript{\alph*},%
  ref=\alph*,%
  itemsep=\z@,%
  topsep=\medskipamount,%
  partopsep=\z@skip,%
  parsep=\z@,%
  itemindent=\z@,%
  labelindent=\tabcolsep,%
  labelsep=.2em,%
  leftmargin=*,%
  align=left,%
  before={\footnotesize}%
}

\makeatother

\begin{table}
  \begin{threeparttable}
    \caption{Third Attempt: Case 1}
    \begin{tabularx}\linewidth{Xl}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabularx}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\begin{table}
  \begin{threeparttable}
    \caption{Third Attempt: Case 2}
    \begin{tabular}{ll}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabular}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\end{document}

[编辑删除之前编辑中添加的更多最小案例,事实证明这些案例更加最小,但并非实际案例。

答案1

在此处输入图片描述

这是tabular宽度测量代码的threeparttable作用。(tabular*并且tabularx具有明确的宽度,因此threeparttable只使用指定的宽度,并且在这些情况下不测量任何东西。)

以下更改通过保留值来消除更改,\prevdepth因此以下文本(示例中的注释)的基线计算不受影响。

现有代码明确将设置\prevdepth为 0pt,因此显然是故意的,但没有记录。我在这里做了修改,但作者threeparttable对 TeX 框操作的理解往往是正确的,所以也许我遗漏了一些东西。然而......

\documentclass{article}
\usepackage{tabularx}
\usepackage{threeparttable}

\makeatletter

\def\TPT@measurement{%
 \ifdim\wd\@tempboxb<\TPTminimum
  \hsize \TPTminimum
 \else
  \hsize\wd\@tempboxb
 \fi
 \xdef\TPT@hsize{\hsize\the\hsize \noexpand\@parboxrestore}\TPT@hsize
 \ifx\TPT@docapt\@undefined\else
  \TPT@docapt \vskip.2\baselineskip
 \fi \par 
\dimen@\dp\@tempboxb % new
\box\@tempboxb
 \ifvmode \prevdepth\dimen@ \fi% was \z@ not \dimen@
}
\makeatother

\usepackage{enumitem}
\makeatletter
\renewlist{tablenotes}{enumerate}{1}
\setlist[tablenotes]{label=\textsuperscript{\alph*},ref=\alph*,itemsep=\z@,topsep=\z@skip,partopsep=\z@skip,parsep=\z@,itemindent=\z@,labelindent=\tabcolsep,labelsep=.2em,leftmargin=*,align=left,before={\footnotesize}}
\makeatother

\parindent=0pt


\begin{document}
\begin{table}
  \begin{threeparttable}
    \caption{Initial Attempt: Case 1}
    \begin{tabularx}\linewidth{Xl}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabularx}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\begin{table}
  \begin{threeparttable}
    \caption{Initial Attempt: Case 2}
    \begin{tabular}{ll}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabular}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}


\makeatletter

\setlist[tablenotes]{label=\textsuperscript{\alph*},ref=\alph*,itemsep=\z@,topsep=\z@skip,partopsep=\z@skip,parsep=\z@,itemindent=\z@,labelindent=\tabcolsep,labelsep=.2em,leftmargin=*,align=left,before={\unskip\medskip\footnotesize}}

\makeatother

\begin{table}
  \begin{threeparttable}
    \caption{Second Attempt: Case 1}
    \begin{tabularx}\linewidth{Xl}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabularx}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\begin{table}
  \begin{threeparttable}
    \caption{Second Attempt: Case 2}
    \begin{tabular}{ll}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabular}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\makeatletter

\setlist[tablenotes]{%
  label=\textsuperscript{\alph*},%
  ref=\alph*,%
  itemsep=\z@,%
  topsep=\medskipamount,%
  partopsep=\z@skip,%
  parsep=\z@,%
  itemindent=\z@,%
  labelindent=\tabcolsep,%
  labelsep=.2em,%
  leftmargin=*,%
  align=left,%
  before={\footnotesize}%
}

\makeatother

\begin{table}
  \begin{threeparttable}
    \caption{Third Attempt: Case 1}
    \begin{tabularx}\linewidth{Xl}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabularx}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\begin{table}
  \begin{threeparttable}
    \caption{Third Attempt: Case 2}
    \begin{tabular}{ll}
      \hline
      here is some test & and some more stuff here\\
      \hline
    \end{tabular}

    \begin{tablenotes}
      \item Yertle the turtle was King of the Pond \dots.
      \item I'm OK.
    \end{tablenotes}
  \end{threeparttable}
\end{table}

\end{document}

相关内容