Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
\csvreader[tabular=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}

enter image description here

share|improve this question

2 Answers 2

up vote 8 down vote accepted

You want to use longtable:

\documentclass{article}

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

\csvreader[
  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}

\csvreader[
  longtable=lrrrr,
  table head=
    \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}
share|improve this answer
    
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 (\%) \\
\midrule \endhead
\bottomrule \endfoot
\csvreader[
    late after line=\\,
    late after last line=,
    before reading={\catcode`\#=12},
    after reading={\catcode`\#=6}]%
    {mode1_with.csv}{1=\Item,2=\Percentage}{\Item & \Percentage}
\end{longtable}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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