1

LaTeX gives me an error every time I add the line containing the filter. It works fine without the filter. What have I done wrong?

Here is my LaTeX entry:

\documentclass{article}
\usepackage{float}
\renewcommand{\baselinestretch}{0}  %spacing between lines of a same paragraph
\usepackage[margin=1in,includefoot]{geometry}           %set margins
\usepackage{tabulary}
\usepackage{tabularx}
\usepackage{csvsimple,filecontents,longtable}
\usepackage{array}
\usepackage{etoolbox}
\usepackage{booktabs}
\begin{document}

\begin{filecontents*}{random.csv}
A,  B,  C
egfwgt, 36, ery
wrgsreh,    3645467,    yfghs
rshgtesh,   346,    rsth
ethshs, 365,    sty
\end{filecontents*}

\begin{table}[H]
        \setlength{\extrarowheight}{0.2in}
        \begin{center}
        \csvreader 
            [tabular=ccc,
            table head= \toprule A & B & C \\ \midrule,
            table foot= \bottomrule, 
            filter test=\ifnumgreater{\B}{300},
            ]%
            {random.csv}{A=\A, B=\B, C=\C}%
            {\A  & \B & \C}
        \end{center} \end{table}

\end{document}
  • Yes, it is on a csv file, I just wanted to show what was on it. It's really the filter that's the problem since it works fine when I add a '%' in front of my filter. the error given is 'package pgfkeys Error'. Thank you for your quick answer, I am very new to LaTex :) – Valerie Desjardins May 2 '17 at 19:57
  • Have you tried full filter={\ifnum\B>300\csvfilteraccept\else\csvfilterreject\fi} too? – user31729 May 2 '17 at 20:51
3

As you probably already noticed the input has to be comma separated values, thus now the input is correct. Next look at page 18 in the manual, it has an example that makes this work, resulting in using

full filter= \ifnumgreater{\B}{300}{\csvfilteraccept}{\csvfilterreject},

According to the manual filter=... is the same as filter ifthen=... and thus only constructions from the ifthenpackage are viable.

For reference here is my complete, working example, with irrelevant (for this question) stuff removed (running on texlive 2016)

\documentclass{article}
\usepackage{csvsimple,filecontents,longtable}
\usepackage{etoolbox}
\usepackage{booktabs}

\begin{filecontents*}{random.csv}
A,B,C
egfwgt,36,ery
wrgsreh,3645467,yfghs
rshgtesh,346,rsth
ethshs,365,sty
\end{filecontents*}



\begin{document}


            \csvreader 
                [tabular=ccc,
                table head= \toprule A & B & C \\ \midrule,
                late after line= \\,
                table foot= \bottomrule, %very important to put line at bottom
                full filter= \ifnumgreater{\B}{300}{\csvfilteraccept}{\csvfilterreject},
                ]%
                {random.csv}{A=\A, B=\B, C=\C}%
                {\A  & \B & \C}



\end{document}

BTW please don't use the float package and the [H] option for floats, better learn to use floats properly.

  • hi! The code you gave is working on my coworkers computer (a Window), but not on my Mac. Do you think this is the problem? – Valerie Desjardins May 2 '17 at 20:37
  • @ValerieDesjardins versions! Which latex installation and version are you running on your mac? It is usually listed at the top of the log file that latex creates when you compile. – daleif May 2 '17 at 20:40
  • Mine is listing This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex 2017.3.7) 2 MAY 2017 22:25 The version of csvsimpleI have is from July. – daleif May 2 '17 at 20:41
  • Mine is This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex 2016.5.22) so i guess its an updated version of latex? – Valerie Desjardins May 2 '17 at 20:42
  • Has this MacTeX ever been updated? You can see the version of csvsimple by looking at the manual you have on disk, run texdoc csvsimple in a terminal. – daleif May 2 '17 at 20:45

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.