0

Is there a limit to the number of columns longtable can handle? I keep getting errors when I try to input seven columns. Code below:

\begin{filecontents*}{sample_data.csv}
    Col1,Col2,Col3,ColPct,Col5,Col6,Col7
    111,65,64,5\%,a,b,c
    112,30,5,6\%,a,b,c
    113,92,1,8.4\%,a,b,c
    114,47,19,20\%,a,b,c
    115,38,15,1\%,a,b,c
\end{filecontents*}

\documentclass{article}

\usepackage{csvsimple,longtable,booktabs}
\begin{document}

    \csvreader[
    longtable=lrrrr,
    table head=
    \toprule\bfseries Col1 &\bfseries Col2 & \bfseries Col3 & \bfseries ColPct & \bfseries Col5 & \bfseries Col6 & \bfseries Col7\\ 
    \midrule\endhead\bottomrule\endfoot,
    late after line=\\,
    before reading={\catcode`\#=12},after reading={\catcode`\#=6}
    ]{sample_data.csv}{1=\One,2=\Two, 3=\Three, 4=\Four, 5=\Five,6=\Six,7=\Seven}
    {\One & \Two & \Three & \Four & \Five & \Six & \Seven}
\end{document}
1

While \csvautolongtable can handle 7 columns, it does not allow you to specify the column formats. So I replaced the definition of autolongtable (which is implemented as a keyword).

I left out the sample_data.csv definition, since you already have the file.

\documentclass{article}

\usepackage{csvsimple,longtable,booktabs}

\makeatletter
\newcommand{\longtableformat}{|*{\csv@columncount}{l|}}% default
\csvset{autolongtable/.style={
    file=#1,
    after head=\csv@pretable\begin{longtable}{\longtableformat}\csv@tablehead,% replaced default column formats
    table head=\hline\csvlinetotablerow\\\hline\endhead\hline\endfoot,
    late after line=\\,
    late after last line=\csv@tablefoot\end{longtable}\csv@posttable,
    command=\csvlinetotablerow}}
\makeatother

\begin{document}

\def\longtableformat{lrrrccc}%
\csvautolongtable{sample_data.csv}

\end{document}

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.