csvpaginationlatex

How to auto paginate a large CSV table in LaTeX?


I have the following LaTeX document:

\documentclass{article}

\usepackage{csvsimple}
\usepackage{adjustbox}

\begin{document}

\begin{table}[htb]\centering
    \adjustbox{max width=\textwidth}{
    \csvreader[
        respect all,
        tabular=|c|c|c|c|c|c|c|c|,
        table head=\hline ID & Project & Summary & Type & Component(s) & Description & Module & Version \\ \hline\hline,
        late after line=\\\hline
    ]{random_data.csv}{}
    {\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii}
    }
\end{table}

\end{document}

The CSV file is a simple 8-column with 400 lines, containing random values, such as:

50,9,81,85,79,96,46,33
3,24,63,91,8,82,95,55
9,72,72,40,76,40,66,12
57,71,67,58,30,83,95,93
... 400 lines ...

How can I convert this LaTeX document to a PDF where the table is divided across multiple pages, depending on the CSV lines?

I tried using longtable, but run into compiling issues. The latex code like this is perfect I just really need the pagination part.


Solution


  • \documentclass{article}
    
    \usepackage{csvsimple}
    \usepackage{longtable}
    
    \begin{filecontents*}[overwrite]{random_data.csv}
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    50,9,81,85,79,96,46,33
    3,24,63,91,8,82,95,55
    9,72,72,40,76,40,66,12
    57,71,67,58,30,83,95,93
    \end{filecontents*}
    
    \begin{document}
    
    %\begin{table}[htb]\centering
    %    \adjustbox{max width=\textwidth}{
        \csvreader[
            respect all,
            longtable=|c|c|c|c|c|c|c|c|,
            table head=\hline ID & Project & Sum. & Type & Comp. & Desc. & Module & Version \\ \hline\hline,
            late after line=\\\hline
        ]{random_data.csv}{}
        {\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii}
    %    }
    %\end{table}
    
    \end{document}