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

Problem. When coloring a table, using different colors for even / odd rows is quite usual and can be accomplished with the xcolor package. I, however, don't want to have alternating colors per row, but per row group.

Example. The following example is minimal working. I have a macro \writerow to output a table row (because much information in the original file is automatically generated), and I have a second macro \setgroup to set the group to 1 (white background) or 2 (gray background). To store this information, there is a macro \rc (reading "row color").




% Macros

        \\ \rowcolor[gray]{\rc} #1

% Data

                \writerow{Zeile 1}
                \writerow{Zeile 2}
                \writerow{Zeile 3}
                \writerow{Zeile 4}


Presumptions. The example works; however, every row is colored gray, which means that the \renewcommand\rc isn't working. Why?

Probably it's a problem of scope. But the only scope I can see in that document is that of the tabular environment, which shouldn't be a problem, as all the operations happen inside of it.

Where is my error? Thanks for your help in advance!

share|improve this question
Each cell of a table is a scope, so you need to make your commands global. use \gdef rather than \renewcommand – David Carlisle Mar 3 '12 at 12:14
Hey @David, thanks for your comment. That works like a charm! If you don't want to post this as a solution, I'll do so as soon as I'm allowed to. – fxnn Mar 3 '12 at 15:39
up vote 4 down vote accepted

Each cell of a table is a scope, so you need to make your commands global. use \gdef rather than \renewcommand as LaTeX doesn't offer a LaTeX-interface to global settings.

share|improve this answer
Does LaTeX3 have an interface for global settings? – Martin Schröder Mar 23 '12 at 22:36
@MartinSchröder \cs_new:Npn is possibly the nearest thing at the code level to this. (with some help in chat from @egreg and @JosephWright) – David Carlisle Mar 23 '12 at 22:47

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.