1

I am currently creating a threeparttable with longtable and the dcolumn package in order to align my numbers by ".". Under my caption I want to write a description of the table. I am following suggestions of previous threads and try to use the multicolumn functionality to solve that issue. But this does not work, because the rest of my table is suddenly moved. Does someone have a suggestion on how to resolve this?

My code:

\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}

I want my table to look like this: (example without the multicolumn text) enter image description here

But sadly i get this:

enter image description here

I tried multiple things such as using the xltabular package instead of the longtable package, specifying different "p{}" but none seem to work.

3
  • \extracolsep is only used at the end so to fit the wide multicolumn the last column is made wider. (the multicolumn is too wide as \textwidth will not fit as there is \tabcolsep padding either side, but that is not the issue here) Simplest would be to put the paragraph in the caption Commented Feb 2, 2021 at 12:01
  • Thanks for the answer. Yes I also thought about putting the paragraph into the caption. But then my List of Tables yields the whole paragraph as the title Edit: Found a solution. [tex.stackexchange.com/questions/83392/…
    – Conway
    Commented Feb 2, 2021 at 12:13
  • Your code is not compilable since the definition of the d column type and the booktabs package are missing.
    – leandriis
    Commented Feb 2, 2021 at 20:03

1 Answer 1

1

A solution with 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}

enter image description here

2
  • Nice solution! +1!
    – Zarko
    Commented Oct 13, 2023 at 0:20
  • @Zarko Thank you!
    – CarLaTeX
    Commented Oct 13, 2023 at 1:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .