在 tabularray 中复制 threeparttable 的 tablenotes

在 tabularray 中复制 threeparttable 的 tablenotes

Simon Dispa 的精彩回答para, flushleft对我的最后一个问题来说,在复制表格注释的变体方面取得了很大进展threeparttable。但格式threeparttable(之后一些调整) 在我看来通常看起来更好,因为它更好地遵守了右边距。

有没有办法复制这种行为tabularray?或者至少在下面的例子中改进它的行为?

\documentclass{article}
\usepackage{tabularx,booktabs}
\usepackage[para, flushleft]{threeparttable}
\makeatletter
\def\TPT@doparanotes{\par% Alter threeparttable's excessive linebreaks before new notes: https://tex.stackexchange.com/a/564293/71332
   \prevdepth\z@ \TPT@hsize
   \TPTnoteSettings
   \parindent\z@ \pretolerance 8
   \linepenalty 200
   \renewcommand\item[1][]{\relax\ifhmode \begingroup
       \unskip
       \penalty -45 \hskip\z@\@plus 10pt\penalty-19
       \hskip 25pt \penalty 9999 \hskip-25pt
       \hskip 1em\@plus3pt
      \endgroup\fi
      \tnote{##1}\,\ignorespaces}%
   \let\TPToverlap\relax
   \def\endtablenotes{\par}%
}
\makeatother

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\SetTblrStyle{note-tag}{font=\rmfamily}

% Simon Dispa's emulation of threeparttable: https://tex.stackexchange.com/a/616081/71332
\DefTblrTemplate{remark-sep}{three}{:\space}
\DefTblrTemplate{note-sep}{three}{\,}

\DefTblrTemplate{remark}{inline-noclosingpar}{% similar to the remark plain
\MapTblrRemarks{%
  \noindent%
  \UseTblrTemplate{remark-tag}{default}%
  \UseTblrTemplate{remark-sep}{three}%
  \UseTblrTemplate{remark-text}{default}%
  \space\space}
}

\DefTblrTemplate{note}{inline-three}{%
  \MapTblrNotes{%
    \noindent%
    \UseTblrTemplate{note-tag}{default}%
    \UseTblrTemplate{note-sep}{three}%
    \UseTblrTemplate{note-text}{default}%
    \space%
  }
}

\DefTblrTemplate{lastfoot}{mytemplate}{%
  \UseTblrTemplate{remark}{inline-noclosingpar}%
  \UseTblrTemplate{note}{inline-three}%
}

\NewTblrTheme{mytheme}{%
  \SetTblrTemplate{lastfoot}{mytemplate}%
}

\begin{document}
  \begin{table}
    \begin{threeparttable}
      \caption{A \texttt{threeparttable} table with adjusted \texttt{tablenotes}}
      \begin{tabularx}{\linewidth}{@{}Xcc@{}}
        \toprule
        & A & B \\
        \midrule
        A row heading\tnote{a} & a & 123 \\
        Another row heading\tnote{b} & b & 456 \\
        Yet another row heading & c & 789 \\
        \bottomrule
      \end{tabularx}
      \begin{tablenotes}
        \emph{Note}: A few words describing something noteworthy.
        \emph{Source}: Made up by me.
        \item[a] A table footnote that goes on for a few words more than this.
        \item[b] Another table footnote that goes on for a few words more than this.
      \end{tablenotes}
    \end{threeparttable}
  \end{table}

  \begin{table}
    \begin{booktabs}[
      tall,
      theme=mytheme,
      caption={A \texttt{tabularray} table emulating a \texttt{threeparttable}},
      remark{Note}={A few words describing something noteworthy.},
      remark{Source}={Made up by me.},
      note{a}={A table footnote that goes on for a few words more than this.},
      note{b}={Another table footnote that goes on for a few words more than this.}
    ]{
      colspec={@{}Xcc@{}},
      width=\linewidth
    }
      \toprule
      & A & B \\
      \midrule
      A row heading\TblrNote{a} & a & 123 \\
      Another row heading\TblrNote{b} & b & 456 \\
      Yet another row heading & c & 789 \\
      \bottomrule
    \end{booktabs}
  \end{table}
\end{document}

截屏

答案1

注释之间的间距threeparttable似乎太大,所以我(也)更改了它。

A

\documentclass{article}
\usepackage{tabularx,booktabs}
\usepackage[para, flushleft]{threeparttable}
\makeatletter
\def\TPT@doparanotes{\par% Alter threeparttable's excessive linebreaks before new notes: https://tex.stackexchange.com/a/564293/71332
    \prevdepth\z@ \TPT@hsize
    \TPTnoteSettings
    \parindent\z@ \pretolerance 8
    \linepenalty 200
    \renewcommand\item[1][]{\relax\ifhmode \begingroup
        \unskip
        \penalty -45 \hskip\z@\@plus 10pt\penalty-19
        \hskip 25pt \penalty 9999 \hskip-25pt
        \hskip 1ex\@plus3pt % corrected  1ex instead of 1em <<<<<<<<<<
        \endgroup\fi
        \tnote{##1}\,\ignorespaces}%
    \let\TPToverlap\relax
    \def\endtablenotes{\par}%
}
\makeatother

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\SetTblrStyle{note-tag}{font=\rmfamily}

% Simon Dispa's emulation of threeparttable: https://tex.stackexchange.com/a/616081/71332
\DefTblrTemplate{remark-sep}{three}{:\space}
\DefTblrTemplate{note-sep}{three}{\,}

\DefTblrTemplate{remark-text}{three}{\InsertTblrRemarkText\!}% added <<<<<<<<<<<
\DefTblrTemplate {note-text}{three}{\InsertTblrNoteText\!}% added <<<<<

\DefTblrTemplate{remark}{inline-noclosingpar}{% similar to the remark plain
    \MapTblrRemarks{%
        \noindent%
        \UseTblrTemplate{remark-tag}{default}%
        \UseTblrTemplate{remark-sep}{three}%
        \UseTblrTemplate{remark-text}{three}%
        \space\space}
}

\DefTblrTemplate{note}{inline-three}{%
    \MapTblrNotes{%
        \noindent%
        \UseTblrTemplate{note-tag}{default}%
        \UseTblrTemplate{note-sep}{three}%
        \UseTblrTemplate{note-text}{three}%
        \space%
    }
}

\DefTblrTemplate{lastfoot}{mytemplate}{%
    \UseTblrTemplate{remark}{inline-noclosingpar}%
    \UseTblrTemplate{note}{inline-three}%
}

\NewTblrTheme{mytheme}{%
    \SetTblrTemplate{lastfoot}{mytemplate}%
}

\begin{document}
    \begin{table}
        \begin{threeparttable}
            \caption{A \texttt{threeparttable} table with adjusted \texttt{tablenotes}}
            \begin{tabularx}{\linewidth}{@{}Xcc@{}}
                \toprule
                & A & B \\
                \midrule
                A row heading\tnote{a} & a & 123 \\
                Another row heading\tnote{b} & b & 456 \\
                Yet another row heading & c & 789 \\
                \bottomrule
            \end{tabularx}
            \begin{tablenotes}
                \emph{Note}: A few words describing something noteworthy.
                \emph{Source}: Made up by me.
                \item[a] A table footnote that goes on for a few words more than this.
                \item[b] Another table footnote that goes on for a few words more than this.
            \end{tablenotes}
        \end{threeparttable}
    \end{table}
    
    \begin{table}
        \begin{booktabs}[
            tall,
            theme=mytheme,
            caption={A \texttt{tabularray} table emulating a \texttt{threeparttable}},
            remark{Note}={A few words describing something noteworthy.},
            remark{Source}={Made up by me.},
            note{a}={A table footnote that goes on for a few words more than this.},
            note{b}={Another table footnote that goes on for a few words more than this.}
            ]{
                colspec={@{}Xcc@{}},
                width=\linewidth
            }
            \toprule
            & A & B \\
            \midrule
            A row heading\TblrNote{a} & a & 123 \\
            Another row heading\TblrNote{b} & b & 456 \\
            Yet another row heading & c & 789 \\
            \bottomrule
        \end{booktabs}
    \end{table}
    \hfill
\end{document}

相关内容