threeparttablex 的标题太宽

threeparttablex 的标题太宽

当我使用包ThreePartTable中的标签时threeparttablex,标题不会像常规标签那样尊重表格的宽度threeparttable。我该怎么做?还是我做错了什么……?

\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage[referable]{threeparttablex}
\begin{document}
\begin{ThreePartTable}
\begin{TableNotes}
\item[a] \label{tn:a} test test test test test test test test
\item[b] \label{tn:b} test2
\source Made up by daleif
\end{TableNotes}
\begin{longtable}{l l l}
\caption{A \texttt{ThreePartTable} with a title that is long enough to wrap}\\
\toprule
Coloum 1 & & Column 2 \\
\midrule
\endhead
\cmidrule{3-3}
\multicolumn{3}{r}{\textit{continued}}
\endfoot
\bottomrule
\insertTableNotes\\
\endlastfoot
AAAA\tnotex{tn:a} &
& BBBB \\
%\newpage
CC
&
& DD\tnotex{tn:b}
\\
\end{longtable}
\end{ThreePartTable}
\begin{center}
\begin{threeparttable}
\caption{A \texttt{threeparttable} with a title that is long enough to wrap}
\begin{tabular}{l l l}
\toprule
Coloum 1 & & Column 2 \\
\midrule
AAAA\tnote{c} &
& BBBB \\
CC
&
& DD\tnotex*{tn:c}
\\
\bottomrule
\end{tabular}
\begin{tablenotes}
\footnotesize
\item[c] test test test test test test test test
\item[d] \label{tn:c} the reference to this is not a link
\note Some general note
\end{tablenotes}
\end{threeparttable}
\end{center}
\end{document}

输出

答案1

虽然不太美观,但还是可以做到的。您需要从 longtable 中提取宽度。然后明确设置标题宽度。这就是\insertTableNotes知道表格宽度的方法。

\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable,caption}
\usepackage[referable]{threeparttablex}
\makeatletter
\newcommand{\FixCaptionWidth}{\noalign{\begingroup%
  \setlength\TPTL@width{0pt}%
  \renewcommand\LT@entry[2]{\global\advance\TPTL@width by ##2}%
  \@nameuse{LT@\romannumeral\c@LT@tables}%
  \ifdim\TPTL@width<\TPTminimum\relax\global\TPTL@width=\TPTminimum\fi%
  \endgroup}%
  \captionsetup{width=\TPTL@width}%
}
\makeatother
\begin{document}
\begin{ThreePartTable}
\begin{TableNotes}
\item[a] \label{tn:a} test test test test test test test test
\item[b] \label{tn:b} test2
\source Made up by daleif
\end{TableNotes}
\begin{longtable}{l l l}
\FixCaptionWidth
\caption{A \texttt{ThreePartTable} with a title that is long enough to wrap}\\
\toprule
Coloum 1 & & Column 2 \\
\midrule
\endhead
\cmidrule{3-3}
\multicolumn{3}{r}{\textit{continued}}
\endfoot
\bottomrule
\insertTableNotes\\
\endlastfoot
AAAA\tnotex{tn:a} &
& BBBB \\
%\newpage
CC
&
& DD\tnotex{tn:b}
\\
\end{longtable}
\end{ThreePartTable}  
\begin{center}
\begin{threeparttable}
\caption{A \texttt{threeparttable} with a title that is long enough to wrap}
\begin{tabular}{l l l}
\toprule
Coloum 1 & & Column 2 \\
\midrule
AAAA\tnote{c} &
& BBBB \\
CC
&
& DD\tnotex*{tn:c}
\\
\bottomrule
\end{tabular}
\begin{tablenotes}
\footnotesize
\item[c] test test test test test test test test
\item[d] \label{tn:c} the reference to this is not a link
\note Some general note
\end{tablenotes}
\end{threeparttable}
\end{center}
\end{document}

答案2

我怀疑你正在经历这样的事情:

在此处输入图片描述

这可以通过使用包简单longtblr实现tabularray

\documentclass{article}
%--------------- 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
%---------------------------------------------------------------%

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
    \SetTblrStyle{contfoot-text}{font=\footnotesize\itshape}
    \SetTblrStyle{note}{font=\footnotesize}
    \SetTblrStyle{remark}{font=\footnotesize}
    
\begin{document}
\lipsum[1-4]

    \begin{longtblr}[
caption = {A \texttt{ThreePartTable} with a title that is long enough to wrap},
  label = {longtab:?},
%
note{a} = {test test test test test test test test} ,
note{b} = {test 2},
remark{Source} = {Made up by daleif.}
                    ]{colspec = {*{2}{Q[l, wd=6em]}},
                      rowhead = 1
                      }
    \toprule
Colum 1             &   Column 2           \\
    \midrule
AAAA\TblrNote{a}    &   BBBB               \\
CC                  &   DD DdD DD\TblrNote{b}    \\
    \bottomrule
    \end{longtblr}
\end{document}¸

和软件包longtblr的结合功能。基于 LaTeX3 的语法与“经典”表中的略有不同。它在软件包文档中有详细描述,并且易于学习。threeparttablelongtable

从上面的MWE可以看出,代码简单,简洁,简短,但是它无法引用文档文本中的表格注释。

编辑: 表格标题到目前为止考虑默认格式(仅支持悬挂格式),但可以更改为考虑包中定义的格式caption

\documentclass{article}
%--------------- 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
%---------------------------------------------------------------%

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
    \SetTblrStyle{contfoot-text}{font=\footnotesize\itshape}
    \SetTblrStyle{note}{font=\footnotesize}
    \SetTblrStyle{remark}{font=\footnotesize}
\usepackage{caption}   % <---
\captionsetup[table]{skip=0pt,
                     font = {small, sf},
                     labelfont = bf,
                    %singlelinecheck = off
                    }
\NewTblrTheme{captionof}% <---
{\DefTblrTemplate{caption}{default}%
    {\addtocounter{table}{-1}%
     \captionof{table}{\InsertTblrText{caption}}
    }
 \DefTblrTemplate{capcont}{default}%
    {\addtocounter{table}{-1}%
     \captionof{table}{\InsertTblrText{caption} (continue)}
    }
}
    
\begin{document}
\lipsum[1-4]

A case when caption is defined by \verb+caption+ package:
    \begin{longtblr}[
  theme = captionof,  % <---
caption = {A \texttt{ThreePartTable} with a title that is long enough to wrap.},
  label = {longtab:?},
%
note{a} = {test test test test test test test test  \label{tn:a}} ,
note{b} = {test 2  \label{tn:b}},
remark{Source} = {Made up by daleif.}
                    ]{colspec = {*{2}{Q[l, wd=7em]}},
                      rowhead = 1
                      }
    \toprule
Colum 1             &   Column 2           \\
    \midrule
AAAA\TblrNote{a}    &   BBBB               \\
CC                  &   DDD DDD DD\TblrNote{b}    \\
    \bottomrule
    \end{longtblr}  
\end{document}

在此处输入图片描述

相关内容