5

I am using color tables in my document, as it produces very nice results. Further to that I use some equations using cases environment. I see that the colors from the color table get mixed up with the equations.

How to remove the effect of color table once I finished using it in a table. Here is a MWE to reproduce the problem. If I un-comment the line \rowcolors{2}{white}{white}, I see that the half brace goes missing.

\documentclass{article}

\usepackage[table,rgb,hyperref]{xcolor}
\usepackage{hhline}
\usepackage{multirow}
\usepackage{amsmath}

\begin{document}

\rowcolors{2}{white}{gray!25}
\begin{table}[h]
    \centering
    \begin{tabular}{cccc}
        \hline
        & \multicolumn{3}{c}{$TxCost_p$} \\\hhline{~---}
        \multirow{-2}{*}{p} & min   & max    & avg   \\\hline\hline
        1 & 1.13  & 14.00  & 2.57  \\\hline
        2 & 1.78  & 29.98  & 4.13  \\\hline
        4 & 3.97  & 47.23  & 11.07 \\\hline
        8 & 5.43  & 87.86  & 18.82\\\hline
    \end{tabular}
\caption{performance }
\end{table}
%\rowcolors{2}{white}{white}


\begin{equation}
    Time = \begin{cases}
        m \cdot C + 2 T & \mbox{in the computation }\\ 
        (m+1) \cdot T & \mbox{in the transfer }
    \end{cases}
\end{equation}

\end{document}

and here is the screenshot

enter image description here

3
  • 2
    I am pretty sure, that \rowcolors command must be within \begin{table}...\end{table}, not outside
    – user31729
    Commented Jun 19, 2014 at 16:17
  • @ChristianHupfer got the mistake ! I think I copied from the wrong example. thanks. Commented Jun 19, 2014 at 16:23
  • 1
    You may consider to accept the answer by user LaRiFari below too, to close this question.
    – user31729
    Commented Jun 19, 2014 at 16:25

1 Answer 1

8

The command \rowcolors{}{}{} has to be situated inside your table environment.

% arara: pdflatex

\documentclass{article}

\usepackage[table,rgb,hyperref]{xcolor}
\usepackage{hhline}
\usepackage{multirow}
\usepackage{amsmath}

\begin{document}
\begin{table}[h]
\rowcolors{2}{white}{gray!25}
    \centering
    \begin{tabular}{cccc}
        \hline
        & \multicolumn{3}{c}{$TxCost_p$} \\\hhline{~---}
        \multirow{-2}{*}{p} & min   & max    & avg   \\\hline\hline
        1 & 1.13  & 14.00  & 2.57  \\\hline
        2 & 1.78  & 29.98  & 4.13  \\\hline
        4 & 3.97  & 47.23  & 11.07 \\\hline
        8 & 5.43  & 87.86  & 18.82\\\hline
    \end{tabular}
\caption{performance }
\end{table}

\begin{equation}
    Time = \begin{cases}
        m \cdot C + 2 T & \mbox{in the computation }\\ 
        (m+1) \cdot T & \mbox{in the transfer }
    \end{cases}
\end{equation}
\end{document}

enter image description here

And here, how I would have done it:

% arara: pdflatex

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{mathtools}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}
\rowcolors{2}{white}{gray!25}
    \centering
    \begin{tabular}{cS[table-format=1.2]S[table-format=2.2]S[table-format=2.2]}
\toprule
       \multirow{2}*{$p$} & \multicolumn{3}{c}{$Tx\text{Cost}_p$} \\\cmidrule(l){2-4}
        & {min}   & {max}    & {avg}   \\
        1 & 1.13  & 14.00  & 2.57  \\
        2 & 1.78  & 29.98  & 4.13  \\
        4 & 3.97  & 47.23  & 11.07 \\
        8 & 5.43  & 87.86  & 18.82\\\bottomrule
    \end{tabular}
\caption{performance }
\end{table}

\begin{equation}
    Time = \begin{cases}
        m \cdot C + 2 T & \text{in the computation }\\ 
        (m+1) \cdot T & \text{in the transfer }
    \end{cases}
\end{equation}
\end{document}

enter image description here

1
  • how do you use it with longtable?
    – chuse
    Commented Oct 21, 2021 at 11:02

You must log in to answer this question.

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