1

I am using csvreader with longtable and I added a caption in table head below is my code:

\csvreader[
  longtable=ccc,
  table head=\caption{Caption goes here.
}\label{tab:sometab} \\
    \toprule\bfseries id &\bfseries gene &\bfseries name \\ \midrule\endhead
    \bottomrule\endfoot,
  late after line=\\,
]{app/fsnewtax.csv}{1=\id,2=\gene,3=\name}{\id&\gene&\name}

This is part of the csv file:

23271,cox3,Poec
685,cox3,Pier
5,atp6,Luc
85,atp6,Mut
16,nad3,Ans
55,nad3,Ple
13,nad3,Geo

The problem is: the caption is repeated on every page of the table, I want it to be just on the first page. How to do this ? I couldn't find anything related to adding caption in the csvsimple documentation.

2

Your problem is very simple to solve, just use \endfirsthead after what you want on the first page and \endhead after what you want on the following pages. See longtable package documentation.

I repeated your data many times in the fsnewtax.csv of my MWE to have a table two page long.

Moreover, I put the label inside the caption description without going to a new line, otherwise the caption is not correctly centered.

\begin{filecontents*}{fsnewtax.csv}
23271,cox3,Poec
685,cox3,Pier
5,atp6,Luc
85,atp6,Mut
16,nad3,Ans
55,nad3,Ple
13,nad3,Geo
23271,cox3,Poec
685,cox3,Pier
5,atp6,Luc
85,atp6,Mut
16,nad3,Ans
55,nad3,Ple
13,nad3,Geo
23271,cox3,Poec
685,cox3,Pier
5,atp6,Luc
85,atp6,Mut
16,nad3,Ans
55,nad3,Ple
13,nad3,Geo
23271,cox3,Poec
685,cox3,Pier
5,atp6,Luc
85,atp6,Mut
16,nad3,Ans
55,nad3,Ple
13,nad3,Geo
23271,cox3,Poec
685,cox3,Pier
5,atp6,Luc
85,atp6,Mut
16,nad3,Ans
55,nad3,Ple
13,nad3,Geo
23271,cox3,Poec
685,cox3,Pier
5,atp6,Luc
85,atp6,Mut
16,nad3,Ans
55,nad3,Ple
13,nad3,Geo
23271,cox3,Poec
685,cox3,Pier
5,atp6,Luc
85,atp6,Mut
16,nad3,Ans
55,nad3,Ple
13,nad3,Geo
23271,cox3,Poec
685,cox3,Pier
5,atp6,Luc
85,atp6,Mut
16,nad3,Ans
55,nad3,Ple
13,nad3,Geo
23271,cox3,Poec
685,cox3,Pier
5,atp6,Luc
85,atp6,Mut
16,nad3,Ans
55,nad3,Ple
13,nad3,Geo
\end{filecontents*} 
\documentclass{article} 
\usepackage{csvsimple}
\usepackage{longtable}
\usepackage{booktabs}
\begin{document} 
\csvreader[
  longtable=ccc,
  table head=\caption{Caption goes here.\label{tab:sometab}}\\
    \toprule\bfseries id &\bfseries gene &\bfseries name \\ \midrule\endfirsthead
    \toprule\bfseries id &\bfseries gene &\bfseries name \\ \midrule\endhead
    \bottomrule\endfoot,
  late after line=\\,
]{fsnewtax.csv}{1=\id,2=\gene,3=\name}{\id&\gene&\name}
\end{document}

enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.