TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following MWE :




\section{display table}



a & b & row-number \\
\a    &    \b & \arabic{DTLrowi}  \\


The \DTLforeach loop runs on all rows for with the test [\DTLiseq{\b}{oui}] is true, i.e. all rows with a=oui or rows 3 and 4. The command \arabic{DTLrowi} delivers the row number of the current row in the loop, but it refers to the "subtable" generated by the restriction [\DTLiseq{\b}{oui}]. In this subtable, they are rows 1 and 2.

My question: I want to refer to the original row numbers (3 and 4 in this case). Is it possible ?

share|improve this question
up vote 3 down vote accepted

The <condition> associated with \DTLforeach[<condition>]{..}{..}{<body>} should then be used within <body>. Furthermore, the result of \DTLiseq{\b}{oui} returns true or false and should then be used in an \ifthenelse{<condition>}{<true>}{<false>} boolean clause:

      {\a    &    \b & \arabic{DTLrowi}  \\}

This definition in your MWE produces:

enter image description here

share|improve this answer
simple and efficient :) I'm nevertheless puzzled, that the original rownumber is not anymore available in the DTLloop with the [test] – nicolas roy Jan 20 '12 at 12:03
@nicolasroy: It is, but it is only stepped (incremented) when the <condition> is true. That's why migration to the body means it the default condition always holds (which is true), stepping the counter at every row, resulting in the correct output. – Werner Jan 20 '12 at 21:41

Your Answer


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.