# Importing CSV file as a table in Latex but file too long

I am trying to import a CSV file but the data in the table is too long it goes down till the end of the page and disappears without continuing on the next page.

Here's the file:

\begin{filecontents*}{mode1_with.csv}
Stimulus,Percentage of 'Alpha'
1,95.8
2,90.6
3,98.8
4,97
5,76.4
6,74.8
7,84.8
8,81.8
9,53.6
10,58.4
11,70.8
12,66.8
13,46.6
14,42.8
15,54
16,52
17,34
18,29.2
19,77.8
20,78.8
21,59.8
22,56.4
23,66.2
24,63.8
25,41.6
26,42.8
27,63.6
28,63.4
29,44
30,40.2
31,49.8
32,48.6
33,80.8
34,80.4
35,90.8
36,89
37,66.4
38,61
39,69.4
40,72.4
41,30.8
42,32.4
43,39.4
44,37
45,18.2
46,20.8
47,13.4
48,30.6
49,83
50,78.4
51,87
52,81.4
53,60.2
54,55.2
55,70.8
56,86.4
57,42.8
58,39.6
59,49.6
60,46.8
61,27
62,27.6
63,78
64,89.4
\end{filecontents*}


and this is the code I tried so far:

\usepackage{csvsimple}
\begin{document}
&\bfseries Alpha category (\%) \\\midrule,
late after line=\\,late after last line=\\\bottomrule,
before reading={\catcode\#=12},after reading={\catcode\#=6}]%
{mode1_with.csv}{1=\Item,2=\Percentage}%
{\Item & \Percentage}%
\end{document}


-

You want to use longtable:

\documentclass{article}

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

longtable=lrrrr,
table head=\toprule\bfseries Item &\bfseries Alpha category (\%) \\\midrule,
late after line=\\,
late after last line=\\\bottomrule,
before reading={\catcode\#=12},after reading={\catcode\#=6}
]{mode1_with.csv}{1=\Item,2=\Percentage}{\Item & \Percentage}

\end{document}


If you want the header and the bottom rule to be repeated in each page, use

\documentclass{article}

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

longtable=lrrrr,
\toprule\bfseries Item &\bfseries Alpha category (\%) \\ \midrule\endhead
\bottomrule\endfoot,
late after line=\\,
before reading={\catcode\#=12},after reading={\catcode\#=6}
]{mode1_with.csv}{1=\Item,2=\Percentage}{\Item & \Percentage}

\end{document}

-
In your setup, the header row seems to be missing on the second page. –  Mico Aug 17 at 19:51
@Mico It's easy to do it without using \csvreader inside a table. –  egreg Aug 17 at 19:56

You need to use a longtable rather than a tabular environment. If you longtable's native syntax, it's straightforward to retain full control over items such as header and footer material on every page. However, as @egreg's parallel answer shows, it's possible to do so using csvreader's syntax as well.

\documentclass{article}
\usepackage{booktabs,csvsimple,longtable}
\begin{document}
\begin{longtable}{lr}
\toprule
\bfseries Item & \bfseries Alpha category (\%) \\
before reading={\catcode\#=12},