为什么使用多列会改变我的表的其余部分?

为什么使用多列会改变我的表的其余部分?

我目前正在使用 longtable 和 dcolumn 包创建一个 threeparttable,以便按“。”对齐我的数字。在我的标题下,我想写一个表格描述。我按照之前线程的建议尝试使用多列功能来解决该问题。但这不起作用,因为我的表格的其余部分突然移动了。有人对如何解决这个问题有什么建议吗?

我的代码:

\documentclass[
    fontsize=12pt, 
    twoside=off 
]{scrbook}

\usepackage{caption}
\usepackage[flushleft]{threeparttable}
\usepackage{longtable}
\usepackage{threeparttablex}
\usepackage{dcolumn}

\newcolumntype{C}[1]{>{\raggedright\arraybackslash}p{#1}}

\begin{document}
\begin{ThreePartTable}
\small
\renewcommand{\arraystretch}{0.75}
\begin{longtable}{@{\extracolsep{\fill}}ld{1.1}d{1.1}d{1.3}c}

\caption{Some very informative caption}
\label{Table:1} \\  

\multicolumn{5}{C{\textwidth}}{I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text}\\

\toprule
\multicolumn{1}{@{\extracolsep{\fill}}l}{K} & \multicolumn{1}{c}{b} & \multicolumn{1}{c}{t} & \multicolumn{1}{c}{pval} & \multicolumn{1}{c}{R$^2$} \\


\toprule
\endfirsthead

\multicolumn{5}{@{\extracolsep{\fill}}l}{{\bfseries \tablename\ \thetable{} (continued)}}\\
\toprule
\multicolumn{1}{@{\extracolsep{\fill}}l}{K} & \multicolumn{1}{c}{b} & \multicolumn{1}{c}{t} & \multicolumn{1}{c}{pval} & \multicolumn{1}{c}{R$^2$} \\
\toprule   
\endhead

\midrule
\multicolumn{5}{r}{{Continued on next page}} \\
\midrule
\endfoot
\bottomrule
\endlastfoot

\multicolumn{5}{@{\extracolsep{\fill}}l}{Panel A: Hi}\\
\midrule
  10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
  10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
  10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
  10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
  10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
\end{longtable}
\end{ThreePartTable}
\end{document}

我希望我的表格看起来像这样:(没有多列文本的示例) 在此处输入图片描述

但不幸的是我得到了这个:

在此处输入图片描述

我尝试了多种方法,例如使用 xltabular 包而不是 longtable 包,指定不同的“p{}”,但似乎都不起作用。

答案1

解决方案如下tabularray

\documentclass[
    fontsize=12pt, 
    twoside=off 
    ]{scrbook}

\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\sisetup{group-digits=false}

\UseTblrLibrary{booktabs}
\NewColumnType{A}[1][1.2]{Q[si={table-format=#1},c,co=1]}

\DefTblrTemplate{conthead-text}{default}{(continued)}
\SetTblrStyle{caption-tag}{font=\bfseries}

% Code from https://tex.stackexchange.com/a/634814/101651, thanks to L.J.R.
\ExplSyntaxOn
\NewDocumentCommand\FirstOfTwo{m}{
  \exp_last_unbraced:Ne \use_i:nn { #1 }
}
\NewDocumentCommand\SecondOfTwo{m}{
  \exp_last_unbraced:Ne \use_ii:nn { #1 }
}
\ExplSyntaxOff

\DefTblrTemplate{caption-text}{first}{\FirstOfTwo{\InsertTblrText{caption}}}
\DefTblrTemplate{caption-text}{second}{\SecondOfTwo{\InsertTblrText{caption}}}

\DefTblrTemplate{firsthead}{default}{%
  \UseTblrTemplate{caption-tag}{default}%
  \UseTblrTemplate{caption-sep}{default}%
  \UseTblrTemplate{caption-text}{first}%
  \par
}
\DefTblrTemplate{middlehead,lasthead}{default}{%
  \UseTblrTemplate{caption-tag}{default}%
  \UseTblrTemplate{caption-sep}{default}%
  \UseTblrTemplate{caption-text}{second}
  \UseTblrTemplate{conthead-text}{default}%
  \par
}

\begin{document}
\begin{longtblr}[
    caption = {Some very informative caption.\newline I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text. I am writing some text}{Some very informative caption},
    entry = {Some very informative caption},
    label = {Table:1},
    note{a} = {In case you need a specific note.},
    remark{Note} = {In case you need a general note.},
    ]{
    colspec = {Q[si={table-format=2,table-number-alignment=left},c,co=.5]AAA[1.3]Q[si={table-format=1.2,table-number-alignment=right},c,co=.5]}, 
    width = \linewidth,
    rowhead = 2, rowfoot = 1,
    hspan=minimal,
    cell{1}{1}={l},
    cell{1}{Z}={r},
    column{1}={leftsep=0pt},
    column{Z}={rightsep=0pt},
    row{1-2}={guard},
    }
    \toprule
    K & b & t & pval & $\textrm{R}^2$~\\
    \midrule
    \SetCell[c=5]{l} Panel A: Hi\\
    \midrule
    10\TblrNote{a} & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\ 
    10 & 0.10 & 0.10 & 0.100 & 0.00 \\
    \bottomrule
\end{longtblr}
\end{document}

在此处输入图片描述

相关内容