# CSVTools and Lines Every Fifth line [duplicate]

Possible Duplicate:
Checking if a number is a multiple of 4

First, let me apologize for probably a dumb question. I'm trying to make a table, but I want to use CSVTools because, well mostly because its a lot of data and at a personal level I find intermixing all of this stuff kinda ugly. What I need to is create a long table where every fifth line has a horizontal line.

I'm looking at examples 7 and 8 from this document:

http://mirror.hmc.edu/ctan/macros/latex/contrib/csvtools/doc/csvtools.pdf

I know the key to this is somehow modifying this line from example 8:

\ifthenelse{\isodd{\value{csvrownumber}}}{%
\\\rowcolor{green}}{\\\rowcolor{blue}}
}


But what I need (instead off odd) is a remainder term (ie if(remainder(csvrownumber/5)==0){ line }).

Does such a thing exist, is there a better way?

Thanks!

-

## marked as duplicate by Werner, egreg, Paul Gaborit, percusse, Claudio FiandrinoSep 18 '12 at 18:52

csvtools is an obsolete package. It has been replaced by datatool (by the same author). – Alan Munn Sep 15 '12 at 17:45

Here's an ifthen test for every 5th row.

\documentclass{article}

\usepackage{ifthen}

\newcounter{tst}

\begin{document}

\setcounter{tst}{3}

\stepcounter{tst} \thetst: \ifthenelse{\numexpr 5*(\value{tst} / 5) \relax = \value{tst}}{yes}{no}

\stepcounter{tst} \thetst: \ifthenelse{\numexpr 5*(\value{tst} / 5) \relax = \value{tst}}{yes}{no}

\stepcounter{tst} \thetst: \ifthenelse{\numexpr 5*(\value{tst} / 5) \relax = \value{tst}}{yes}{no}

\stepcounter{tst} \thetst: \ifthenelse{\numexpr 5*(\value{tst} / 5) \relax = \value{tst}}{yes}{no}

\stepcounter{tst} \thetst: \ifthenelse{\numexpr 5*(\value{tst} / 5) \relax = \value{tst}}{yes}{no}

\stepcounter{tst} \thetst: \ifthenelse{\numexpr 5*(\value{tst} / 5) \relax = \value{tst}}{yes}{no}

\stepcounter{tst} \thetst: \ifthenelse{\numexpr 5*(\value{tst} / 5) \relax = \value{tst}}{yes}{no}

\stepcounter{tst} \thetst: \ifthenelse{\numexpr 5*(\value{tst} / 5) \relax = \value{tst}}{yes}{no}

\stepcounter{tst} \thetst: \ifthenelse{\numexpr 5*(\value{tst} / 5) \relax = \value{tst}}{yes}{no}

\end{document}

-
Thanks, that worked! – tazz_ben Sep 16 '12 at 3:19

Here is a version that uses the pgf math functions to provide \IfMultipleOf which can be used to test that numbers are multiples of a specified number (defaults to 5):

## Code:

\documentclass{article}
\usepackage{tikz}% easy way to get pgfmath and \foreach
\usepackage{xstring}

\newcommand{\IfMultipleOf}[4][5]{%
% #1 = optional number to determine multiplicity of (defaults to 5)
% #2 = number to test
% #3 = code to execute if multiple of #1
% #4 = code to execute if not multiple of #1
%
\pgfmathsetmacro{\TempRemainder}{mod(#2,#1)}%
\IfEq{\TempRemainder}{0}{#3}{#4}%
}%

\begin{document}

\begin{minipage}{0.45\linewidth}%
\foreach \x in {0,...,10} {%
\x\ \IfMultipleOf{\x}{is}{is not} a multiple of 5\par
}%
\end{minipage}%
\begin{minipage}{0.45\linewidth}%
\foreach \x in {0,...,10} {%
\x\ \IfMultipleOf[3]{\x}{is}{is not} a multiple of 3\par
}%
\end{minipage}%
\end{document}

-

DISCLAIMER NOTE: this is an answer based on pgfplotstable which is neither csvtools nor datatool. I am author of pgfplotstable.

Since the question is tagged as "tables longtable tools", I hope that you find the alternative approach using pgfplotstable useful:

\documentclass{standalone}

\usepackage{pgfplotstable}
\usepackage{booktabs}

\begin{document}
\pgfplotstabletypeset[
every nth row={3}{before row=\midrule},
before row=\toprule,after row=\midrule},
every last row/.style={
after row=\bottomrule},
]{
a b
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
}

\end{document}


This is an extract of the manual at http://pgfplots.sourceforge.net/pgfplotstable.pdf . It uses booktabs to generate header/footer lines. Instead of the inline table (i.e. providing table data inside of curly braces), you can also use a file name, i.e.

\pgfplotstabletypeset[...]{file.csv}

and you can configure the col sep and row sep keys if they are not white space/empty line, resp.

In general, the pgfplotstable package is a generator for LaTeX tabular environments which features - number formatting, - style for columns or rows, - postprocessing (i.e. computing derived columns out of existing ones), - highly configurable interface.

In particular, it supports longtable (see the manual examples for the key begin table).

-