3

I have a document with a defined \rowcolors

Now in a math environment, a cases element is rendered with this table background overlapping the brace:

This can be fixed by adding \rowcolors{1}{}{}

Unfortunately, this does not work in an eqnarray environment.

has no effect and putting it in the cases statement only makes both rows with a white background, still overlaying the brace.

\documentclass[11pt, a4paper, titlepage, german, final]{scrreprt}

\usepackage[table]{xcolor}
\usepackage{color}
\usepackage{multirow}
\usepackage{colortbl}      %puts colors in tables

\definecolor{tr_color1}{HTML}{FFFFFF} %Weiß
\definecolor{tr_color2}{HTML}{E5F2FF} %Blau
\rowcolors{1}{tr_color1}{tr_color2}

\usepackage{amsmath, amssymb, amstext, amsfonts, mathrsfs} % Mathematische Symbole
\begin{document}
\[
    PD(t)= \begin{cases}
    1 : x \\
    0 : y
    \end{cases}
\]

\[\rowcolors{1}{}{}
    PD(t)= \begin{cases}
    1 : x \\
    0 : y
    \end{cases}
\]

\begin{eqnarray*}
    \rowcolors{}{}{}
    d & = & \begin{cases} 1 : PD(i)=1 \\ 0 : PD(i)=0 \end{cases}\\
    z & = & xx
\end{eqnarray*}

\begin{eqnarray*}
    d & = & \begin{cases}\rowcolors{}{}{} 1 : PD(i)=1 \\ 0 : PD(i)=0 \end{cases}\\
    z & = & xx
\end{eqnarray*}
\end{document}

The tip from here (\csname CT@everycr\endcsname{}) does not work either.

So how can I unset the rowcolors inside the eqnarray environmnent?

5
  • Why do you make it so difficult to test your issue? Why don't you show a complete example instead of all this snippets? Apr 11, 2016 at 14:39
  • 1
    also as you have cases you are presumably loading amsmath in which case there really is no use case for using eqnarray The main aim of amsmath is to provide functional alignments to make up for eqnarray's deficiencies. Apr 11, 2016 at 14:57
  • @Ulrike, probably because I missed the part of providing the minimal example doc, sorry
    – Jan
    Apr 11, 2016 at 15:31
  • @David. correct. Which would that be?
    – Jan
    Apr 11, 2016 at 15:32
  • @Jan align normally Apr 11, 2016 at 17:28

3 Answers 3

4

This seems to work; basically, we nullify the action of \@rowc@lors in the amsmath alignments. Of course, I do nothing to eqnarray that should never be used.

\documentclass{article}

\usepackage{amsmath}
\usepackage[table]{xcolor}
\usepackage{etoolbox}

\makeatletter
\pretocmd\env@cases{\def\@rowc@lors{}}{}{}
\pretocmd\start@align{\def\@rowc@lors{}}{}{}
\makeatother

\definecolor{tr_color1}{HTML}{FFFFFF} %Weiß
\definecolor{tr_color2}{HTML}{E5F2FF} %Blau
\rowcolors{1}{tr_color1}{tr_color2}

\begin{document}

\begin{center}
\begin{tabular}{cc}
a & a \\
b & b \\
c & c
\end{tabular}
\end{center}

\[
    PD(t)= \begin{cases}
    1 : x \\
    0 : y
    \end{cases}
\]

\begin{align*}
    d & = \begin{cases} 1 : PD(i)=1 \\ 0 : PD(i)=0 \end{cases}\\
    z & = xx
\end{align*}

\begin{gather*}
a = b \\
c = d
\end{gather*}

\begin{multline*}
a + b \\
c + d
\end{multline*}

\end{document}

enter image description here

4
  • Wow, I will copy this in my document. Cool for having a central solution. One Question: can you explain or point to explanation of \pretocmd\env@cases{\def\@rowc@lors{}}{}{}? I can guess \pretocmd\env@cases and \def But why these extra @ and the order of brace-levels?
    – Jan
    May 12, 2016 at 14:30
  • @Jan \@rowc@lors is the macro that contains the instructions for changing the color after the first row.
    – egreg
    May 12, 2016 at 14:34
  • ah, and the \pretocmd has three arguments, where the first is set to \@rowc@lors{} where the latter two are empty - hence the two pairs of curly braces. Thanks.
    – Jan
    May 12, 2016 at 14:38
  • In order to get it finally working, I had to extend the argument in the \pretocmd\…{} to \def\@rowc@lors{\@rowcolors\@empty}. I could not figure out which of my other usepackages or else could trigger this need. But now it looks as desired.
    – Jan
    Jul 8, 2016 at 7:44
2

You can also disable the rowcolors (locally) with \@rowcolorsfalse (and with \everydisplay{\@rowcolorsfalse} for all display math). But imho the more interesting question is how to color the cases without overwriting the brace. It is not so easy to change the overhang, but this seems to work:

\documentclass[11pt, a4paper, titlepage, german, final]{scrreprt}

\usepackage[table]{xcolor}%
\usepackage{multirow}

\definecolor{tr_color1}{HTML}{FFFFFF} %Weiß
\definecolor{tr_color2}{HTML}{E5F2FF} %Blau
\rowcolors{1}{tr_color1}{tr_color2}

\usepackage{amsmath}
\usepackage{etoolbox,array}

\begin{document}

\makeatletter

\[ \@rowcolorsfalse
    PD(t)=
    \begin{cases}
    1 : x \\
    0 : y
    \end{cases}
\]


\[
    PD(t)=
    \begin{cases}
    1 : x \\
    0 : y
    \end{cases}
\]

\patchcmd\env@cases{@{}l}{@{}>{\columncolor{white}[0.2pt][\tabcolsep]}l}{}{}%


\[
    PD(t)= 
    \begin{cases}
    1 : x \\
    0 : y
    \end{cases}
\]


\end{document}

enter image description here

0

Thanks to @david-carlisle for the answer. (seems he doesn't need the answer reputation :D)

So far the original question is not answered. But the problem arises in a \cases-statement inside an \eqnarray where the rowcolor cannot be unset so far.

This can be bypassed by using normal math environment, where rowcolor unset works and using the aligned-environment from amsmath-package.

\[
    \rowcolors{1}{}{}
    \begin{aligned}
        d & = \begin{cases} 1 : PD(i)=1 \\ 0 : PD(i)=0 \end{cases}\\
        z & = xx
    \end{aligned}
\]

I leave that open in case some can answer the actual question too.

You must log in to answer this question.

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