1

I am reading data for a supplementary info from different CSV files using the csvsimple package. To display things nicely, I have written my own csvstyle, as all the CSV files have the same format. For certain tables, the data is too long and requires multiple pages. This works easily by changing the csvstyle to use long tabularray instead of tabularray. A problem occurs now, when I want to add a caption to this long table: if I wrap the \csvreader and the \caption in e.g. \begin{table}, the table does not do any page breaks anymore; if I use e.g. \begin{longtable} instead of \begin{table}, compilation does not work anymore, each row gets another header row, and things like that, depending on the wrapper.

What is the correct procedure to add a caption here?

Below, a minimum reproducible example with the \begin{table}, that does not do page breaks.

\documentclass{article}
\pagestyle{empty}

\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[table,xcdraw,dvipsnames]{xcolor}
\usepackage[labelfont={bf}, font=small, justification=justified]{caption}
\usepackage[version=4]{mhchem}
\usepackage{chemformula}
\usepackage[separate-uncertainty = true, multi-part-units=single]{siunitx} 
\usepackage{sectsty}
\usepackage{tabularx}
\usepackage{listings}
\usepackage{longtable}
\usepackage{array}
\usepackage{hhline}
\usepackage{booktabs}

% For including csv as tables
\usepackage{tabularray} 
\UseTblrLibrary{siunitx}
\usepackage{csvsimple-l3}

\NewTableCommand\toprule{\hline[0.08em]}
\NewTableCommand\midrule{\hline[0.05em]\vspace{1pt}}
\NewTableCommand\bottomrule{\hline[0.08em]}

\csvstyle{MyStyleLong}{
no head,
before reading=\centering\sisetup{table-number-alignment=center,table-format=3.3,table-auto-round},
long tabularray={
colspec={c@{}S[table-format=3.4]S[table-format=1.2]l},
row{1} = {guard},
column{4} = {cmd=\ch}
},
table head=\toprule\empty & m/z & {Relative Intensity} & Annotation
\\\midrule,
late after line=\\,
late after first line=\\\hline\endhead,
late after last line=,
table foot=\bottomrule,
late after line=\\,
}
 
\begin{filecontents*}[]{test-file-long.csv}
  mz, Intensity, annotation \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH \\
  1.20, 56.01, CH3OH \\
  12.13, 1901.0, CH2OO- + H+\\
  1.20, 56.01, CH3OH
\end{filecontents*}

\begin{document}

\blindtext

% the first empty is for using S as first column
\begin{table}[h]
\caption{Test}
\csvreader[MyStyleLong, filter expr={test{\ifnumgreater{\thecsvinputline}{1}}}]{test-file-long.csv}{}{\empty & \csvcoli & \csvcolii & \csvcoliii }
\end{table}

\end{document}

1 Answer 1

0

The longtblr environment provides the key caption as an option. As far as I saw, csvsimple does not provide any access to these options. However, one can redefine the template's default text in such a way:

\begin{document}

\blindtext

% the first empty is for using S as first column
\DefTblrTemplate{caption-text}{default}{Test}
\csvreader[MyStyleLong, filter expr={test{\ifnumgreater{\thecsvinputline}{1}}}]{test-file-long.csv}{}{\empty & \csvcoli & \csvcolii & \csvcoliii }

\end{document}

You must log in to answer this question.

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