taburowcolors 不会改变行颜色

taburowcolors 不会改变行颜色

我需要突出显示表格上的特殊行。为此,我使用下一个配置:

\documentclass[9pt]{scrreport}
\usepackage{tabu,booktabs}
\usepackage{booktabs}
\usepackage{numprint,siunitx,array}
% the page margins configuration
\usepackage[
    a4paper,
    left=10mm,
    right=10mm,
    top=20mm,
    bottom=20mm
]{geometry}

% allows to change colors for text
\usepackage[dvipsnames,table]{xcolor}
% text align
\usepackage{ragged2e}
% include multi columns text support
\usepackage{multicol}
% use images in document
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{tcolorbox}
% look for images at this place
\graphicspath{ {../assets/images} }
% custom typefaces
\usepackage{fontspec}
\setmainfont[
    Path = ../assets/fonts/,
    Extension = .ttf,
    BoldFont = *_bold.ttf,
]{arial}
\usepackage{anyfontsize}
\fontsize{9}{10}
\usepackage{fancyhdr}

\begin{document}
%... some code
\noindent
\definecolor{lightb}{RGB}{217,224,250}
\begin{table}
    \begin{tabu}{>{\bfseries}lX[l]}
        \toprule
        \taburowcolors[1]3{lightb..white}
        Row1 & 1 \\
        Row2 & 2 \\
    Row3 & 3 \\
        \bottomrule
    \end{tabu}
\end{table}
\end{document}

但我得到的表格没有任何突出显示的行。它看起来像一个简单的表格。

答案1

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\usepackage{xcolor}
\definecolor{ultramarine}{RGB}{0,32,96}
\definecolor{lightb}{RGB}{217,224,250}

\usepackage{amsmath}
\begin{document}
    
    \noindent
    \begin{tblr}{colspec= {Q[c,m]Q[c,m]Q[c,m]Q[c,m]},
            row{odd} = {bg=red!20},
            row{even} = {bg=lightb},
            row{1} = {bg=ultramarine,fg=white, font=\sffamily\bfseries},
        }
%       \toprule%<-------not really required
        Question  
            & Réponse A
                & Réponse B
                    & Réponse C\\ 
        Row1 
            & 1 \\
        Row2 
            & 2 \\
        Row3 
            & 3 \\
%       \bottomrule%<-------not really required
    \end{tblr}
    
    
\end{document}

答案2

这是tabularrayOPtabu表格的模仿品。

OP 的tabu桌子

    \begin{tabu}{>{\bfseries}lX[l]}
        \toprule
        \taburowcolors[1]3{lightb..white}
        Row1 & 1 \\
        Row2 & 2 \\
        Row3 & 3 \\
        \bottomrule
    \end{tabu}

我的tabularray模仿。\taburowcolors行颜色真的循环吗?看看https://github.com/latex3/xcolor/issues/9了解更多信息。

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\usepackage{xcolor}
\definecolor{lightb}{RGB}{217,224,250}
\definecolorseries{tblrow}{rgb}{last}{lightb}{white}

\ExplSyntaxOn
\makeatletter
% #1: name of a color series
% #2: its cycling number
\cs_new:Npn \tblrStepRowColor #1#2
  {
    % make the color series "cycle"
    % i.e., for \resetcolorseries[3]{tblrow}, 
    % colors `tblrow!![0]` and `tblrow!![4]` the same
    \ifnum\numexpr\c@rownum-\c@rownum/#2*#2=0
      \resetcolorseries[#2]{#1}%
    \fi
    \__tblr_cell_gput:ne { background } {#1!!+}
  }
\makeatother
\ExplSyntaxOff

\begin{document}
\resetcolorseries[3]{tblrow}
\begin{tblr}{
  width=\linewidth,
  colspec={>{\bfseries}lX[l]},
  % for each row, apply current color in series `tblrow`
  rows={tblrow!!}, % should be `rows={tblrule}`, 
                   % see issue https://github.com/latex3/xcolor/issues/8
  % here `Z` represents the last column
  column{Z}={appto={\tblrStepRowColor{tblrow}{3}}},
}
  \toprule
  Row1 & 1 \\
  Row2 & 2 \\
  Row3 & 3 \\
  Row1 & 4 \\
  Row2 & 5 \\
  Row3 & 6 \\
  \bottomrule
\end{tblr}
\end{document}

在此处输入图片描述

答案3

尝试nicematrix使用它的\rowlistcolors

\documentclass{article}
\usepackage{booktabs}
\usepackage{nicematrix}

\definecolor{lightb}{RGB}{217,224,250}
\definecolorseries{tblrow}{rgb}{last}{lightb}{white}

\begin{document}
\begin{NiceTabular}[width=\linewidth]{>{\bfseries}lX[l]}
  \CodeBefore
    \resetcolorseries[3]{tblrow}
    \rowlistcolors{1}{tblrow!!,tblrow!![1],tblrow!![2]}
  \Body
    \toprule
    Row1 & 1 \\
    Row2 & 2 \\
    Row3 & 3 \\
    Row1 & 4 \\
    Row2 & 5 \\
    Row3 & 6 \\
    \bottomrule
\end{NiceTabular}
\end{document}

在此处输入图片描述

相关内容