1

I would like to use the cases environment in a table with alternating row colours. Here is some example code.

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

\begin{document}
    \rowcolors{2}{gray!25}{white}
    \begin{tabular}{cc}
        1 & 7\\
        2 & \(\displaystyle
            \begin{cases}
                a & \quad b\\
                c & \quad d
            \end{cases}\)\\
        3 & 4
        \end{tabular}
\end{document}

enter image description here

Unfortunately, this results in the braces being overlapped by white. How can I fix this?

2
  • Welcome to TeX.SX! Please don't post code fragments. Instead, put your fragments into a complete compilable document that shows the problem.
    – BambOo
    Commented Apr 18, 2020 at 10:31
  • 1
    Note that if you simply code \rowcolors{2}{gray!25}{ }, you have no problem.
    – Bernard
    Commented Apr 18, 2020 at 10:49

1 Answer 1

2

See if the following solution fulfill your expectation:

\documentclass[12pt]{article}
\usepackage[table]{xcolor}  %to use direct sum symbol
\usepackage{mathtools}              % <---
\usepackage{cellspace}              % <---
\setlength\cellspacetoplimit{3pt}   % <---
\setlength\cellspacebottomlimit{3pt}% <---

\begin{document}
    \begin{center}
\rowcolors{2}{gray!25}{white}
    \begin{tabular}{cSc}
        1 & 7               \\ 
        2 & \(
            \begin{dcases}   % <---
                a & \quad b\\
                c & \quad d
            \end{dcases}\)  \\ 
        3 & 4
        \end{tabular}
    \end{center}
\end{document}

enter image description here

2
  • Worked great! Two follow up questions 1. What is the difference between dcases and cases? 2. The braces are very close to reaching into other rows - if I want a bit more space between the top and bottom of the cells what can I do? I tried increasing the cellspace limits but it doesn't seem to be working Commented Apr 18, 2020 at 10:25
  • @BaroqueFreak, (i) content in dcases is in \displaystyle while not cases, (ii) if you like to have more space, increase numbers in\setlength\cellspacetoplimit{3pt} \setlength\cellspacebottomlimit{3pt} to desired vertical space.
    – Zarko
    Commented Apr 18, 2020 at 11:42

You must log in to answer this question.

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