xcolor의 rowcolor 차단 여러 줄 괄호

xcolor의 rowcolor 차단 여러 줄 괄호

행마다 다른 색상이 번갈아 나타나는 표를 만들려고 하는데 내 문서가 다음과 같이 컴파일되는 것을 발견했습니다.

색상이 있는 행은 'case' 문의 대괄호를 '덮지만' 색상이 없는 행은 그렇지 않습니다.

행렬 및 기타 큰 중괄호와 비슷한 문제가 있었지만 적분 및 합계와 같은 다른 문제는 발생하지 않았습니다. 나는에 대한 해결책을 살펴 보았습니다.여기그리고여기, 그러나 둘 중 하나를 이해하고 있는지 또는 그것이 내 문제와 어떤 관련이 있는지 잘 모르겠습니다.

내 질문은 이것이 행을 색칠하는 방식에 문제가 있는지 여부와 더 일반적인 방법이 있는지 여부입니다.

내 마크업은 여기에 있습니다:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{amsmath}
\begin{document}

\begin{table}[h]

\renewcommand{\arraystretch}{1.5}%
\rowcolors{2}{}{gray!10} 
\begin{tabular}{p{3cm}|p{5cm}}

    \textbf{Problem} & \\
    With Color & $n! = 
    \begin{cases} 
        1 & \text{if } n = 0 \\
        (n-1)! &  \text{otherwise}
    \end{cases}$ \\

    Without Color & $n! = 
    \begin{cases} 
        1 & \text{if } n = 0 \\
        (n-1)! &  \text{otherwise}
    \end{cases}$ \\

\end{tabular}
\end{table}
\end{document}

답변1

여기에 이미지 설명을 입력하세요

그것은 \left\{\begin{array}{rl} ... \end{array}\right.아마도 당신에게 도움이 될 것입니다:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{amsmath}
\usepackage{array,cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}

\begin{document}
    \begin{table}[h]
\renewcommand{\arraystretch}{1.5}%
\rowcolors{2}{}{gray!10}
\begin{tabular}{p{3cm}|>{$}S{p{5cm}}<{$}}
\textbf{Problem}    & \\
        With Color  & n! = \left\{\begin{array}{rl}
                            1       & \text{if } n = 0 \\[-1ex]
                            (n-1)!  &  \text{otherwise}
                            \end{array}\right. \\
    Without Color   & n! = \begin{cases}
                            1       & \text{if } n = 0 \\
                            (n-1)!  &  \text{otherwise}
                            \end{cases} 
\end{tabular}
    \end{table}
\end{document}

답변2

mathtools(mathtools는 amsmath의 확장임) 대신에 로드 amsmath하고 `dcases* 환경을 사용합니다.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{mathtools}
\begin{document}

\begin{table}[h]
\renewcommand{\arraystretch}{1.5}%
\rowcolors{2}{}{gray!10}
\begin{tabular}{p{3cm}|p{5cm}}
    \textbf{Problem} & \\
    With Color & $n! =
    \begin{dcases*}
        1 & if $ n = 0 $ \\
        (n-1)! & otherwise
    \end{dcases*}$ \\
\end{tabular}
\end{table}

\end{document} 

여기에 이미지 설명을 입력하세요

답변3

{NiceTabular}의 환경은 PGF/Tikz를 사용하여 드로잉하는 nicematrix것과 유사한 도구를 제공합니다 .colortbl

해당 환경을 사용하면 원하는 것을 직접 얻을 수 있습니다(그러나 nicematrixPGF/Tikz 노드를 사용하므로 여러 컴파일이 필요합니다).

\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}
\begin{document}

\begin{table}[h]
\renewcommand{\arraystretch}{1.5}%
\begin{NiceTabular}{p{3cm}|>{\arraybackslash}p{5cm}}%
    [code-before = \rowcolors{2}{}{gray!10}]
    \textbf{Problem} & \\
    With Color & $n! = 
    \begin{cases} 
        1 & \text{if } n = 0 \\
        (n-1)! &  \text{otherwise}
    \end{cases}$ \\
    Without Color & $n! = 
    \begin{cases} 
        1 & \text{if } n = 0 \\
        (n-1)! &  \text{otherwise}
    \end{cases}$ \\
\end{NiceTabular}
\end{table}
\end{document}

위 코드의 출력

관련 정보