0

I'm trying to create a very modular table for a project, where each row is constructed by a command. If I try to set a row color for a table row generated by a command with optional argument, gives the error message:

! Misplaced \noalign.
\rowcolor ->\noalign 
                     {\ifnum 0=`}\fi \global \let \CT@do@color \CT@@do@color...
l.9     \myRowA{bbbb}

Using \cellcolor instead works, just as well as converting the optional argument to a mandatory. Only row colors in combination with optional arguments give that error.

Here is a minimal example showing the problem:

\documentclass{article}
\usepackage[table]{xcolor}

\begin{document}
\newcommand{\myRowA}[2][]{
    \rowcolor{blue} #1 & #2 \\ \hline
}
\begin{tabular}{ll}\hline
    \myRowA{bbbb}
\end{tabular}

\end{document}

Any idea what I'm doing wrong or how I can make this work properly?

  • 1
    commands with optional arguments are not expandable, and this means that \rowcolor is not the first command in the row. – Ulrike Fischer Jan 29 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.