I'm writing a tabular using the spreadtab package for some calculus. I want to write it's rows only under a certain condition, i.e. to test in each of its rows if the condition is true, and then write this row, and not write the row it if the condition is false. All is ok when I do this in a tabular environment, like in this example, where the line of 3 is not written, because '1=2' is false:

1&1         \\  \hline
\ifnum 1=1 2&2 \fi \\ \hline
\ifnum 1=2 3&3 \\ \hline\fi 
\ifnum 1=1 4&4 \fi \\ \hline
End of Tabular

which compiles well like this: enter image description here Now if I insert the same tabular in a spreadtab environment, like in this macro:

\ifnum 1=1 2&2 \fi \\ \hline
\ifnum 1=2 3&3 \\ \hline\fi 
\ifnum 1=1 4&4 \fi \\ \hline

The program doesn't compile and I have this message of error:

! Undefined control sequence.
<argument> 2 \fi \@@nil
l.26 ^^I\end{spreadtab}

what is the problem in my program and how can I repair it ? Thank you

  • The problem with tabular is that it uses its own parser. If it is simple enough, you can replace tabular with lots of \makebox'es. Dec 26, 2015 at 4:40
  • The problem is that it's not simple but I have simplified it. I use this test in statistical calculus Dec 26, 2015 at 5:48

1 Answer 1


If you want to put only text in a cell with spreadtab you simply place somewhere in the cell the character @, this answer show how you can skip & inside the conditional.

The command \condRow with three arguments test if the first argument is equal to 1, the first and second cells of tabular will be the second and third argument of the command.



\newcommand{\condRow}[3]{\ifnum \numexpr#1\relax=1  #2\uppercase{&}#3\\\fi 
\ifnum \numexpr#1\relax=1 \hline\fi}

1&1\\ \hline
3&3\\ \hline 
4&4\\ \hline

  • Thanks for answer. This seems good for simple tests and literal expressions using the @ character. But I have some calculation in my cells ever my condition is true Dec 26, 2015 at 11:02
  • @FaouziBellalouna People can't read your mind.
    – egreg
    Dec 26, 2015 at 11:07
  • Hello @egreg I don't understand.. what do you call "my mind' ? Dec 26, 2015 at 11:58
  • @FaouziBellalouna Your question doesn't mention you want to do computations in the omitted cells
    – egreg
    Dec 26, 2015 at 13:43
  • I want to compute percentile and my test is on when the cumulated frequency is greater then the order of the percentile, and then do (and write !) the computation of this percentile, else do nothing... Dec 26, 2015 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .