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.

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!

share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

3 Answers 3

up vote 3 down vote accepted

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

enter image description here

\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}
share|improve this answer
    
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):

enter image description here

Notes:

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}
share|improve this answer

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},
    every head row/.style={
    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}

enter image description here

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).

share|improve this answer

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