1

Ultimately I want to read a csv (comma separated variable) file into LaTeX and display a table. I'm doing this within the beamer document class. I'm currently using the \csvautobooktabular command from csvsimple to do this, and I've just about got it to work. However I need to exclude the last line and the csv files I'm reading can be an arbitrary length. So I was wondering how I could use \csvfilterreject to eliminate the last line. Here is a simple example of what I'm trying to do:

\documentclass[]{article}
\usepackage{csvsimple}
\usepackage{booktabs}
\usepackage[T1]{fontenc}
\begin{document}
\csvautobooktabular[respect all]{test.csv}
\end{document}

It works with the file test.csv:

a,b,c,d
1,2,3,4
5,6,7,8
9,10,11,12

If this isn't possible using csvsimple, could someone provide me with an example using a different package?


I tried the example in the now accepted answer and I received compilation error:

(/usr/local/texlive/2015/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Fatal fontspec error: "cannot-use-pdftex"
! 
! The fontspec package requires either XeTeX or LuaTeX to function.

It appears I must use XeTeX or LuaTeX to compile this. Is there a way I can avoid this? I'm currently using pdflatex for compiling my documents, and I'm very weary of making such a change.

2
  • 2
    That can't be with my code. I compiles it with pdflatex without no problems. my version is: pdfTeX, Version 3.14159265-2.6-1.40.16 (MiKTeX 2.9 64-bit) . Have you compiled my given code without any changes? If yes, your system has a problem, update it. If not, please compile my without changes. It compiles with only one warning (okay, comming from filecontents). Or used you pdftex instead of pdflatex? – Mensch Sep 25 '15 at 0:09
  • 1
    You're quite right. I'm not sure why this wasn't working for me yesterday, but it works now. Thank you for your help. – John Harrold Sep 25 '15 at 17:10
1

Please try the following MWE:

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.csv}
a,b,c,d
1,2,3,4
5,6,7,8
9,10,11,12
\end{filecontents*}



\documentclass[]{article}
\usepackage{csvsimple}
\usepackage{booktabs}
\usepackage[T1]{fontenc}
\begin{document}
\csvautobooktabular[respect all]{\jobname.csv}

\csvreader[%
  autotabular,
  before filter=\ifthenelse{\equal{\csvcoli}{9}}{\csvfilterreject}{\csvfilteraccept}
]{\jobname.csv}{}{\csvlinetotablerow}%

\end{document}

See page 12 of the documentation. There is the code you only have to change for the if then else condition.

\csvreader[%
      autotabular,
      before filter=\ifthenelse{\equal{\csvcoli}{9}}{\csvfilterreject}{\csvfilteraccept}
    ]{\jobname.csv}{}{\csvlinetotablerow}%

means that if in row 1 (\csvcoli) is a 9, then command \csvfilterreject is executed, which ends all further operations. If not, reading goes on.

0

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.