4

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:

Tabular\\
\begin{tabular}{|c|c|}
\hline
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{tabular}
\\ 
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:

\begin{spreadtab}{{tabular}{|c|c|}}
\hline
1&1\\
\ifnum 1=1 2&2 \fi \\ \hline
\ifnum 1=2 3&3 \\ \hline\fi 
\ifnum 1=1 4&4 \fi \\ \hline
\end{spreadtab}

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

1 Answers1

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.

\documentclass{article}
\usepackage{spreadtab}

\begin{document}

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


\begin{spreadtab}{{tabular}{|c|c|}}
\hline
1&1\\ \hline
@\condRow{1}{34}{202}
3&3\\ \hline 
4&4\\ \hline
\end{spreadtab}

\end{document}
Salim Bou
  • 17,021
  • 2
  • 31
  • 76