2

How can I make a color gradient in a table from the first row to the last row (from top to bottom)?

\documentclass[]{article}
\usepackage{tabularray}
\usepackage{xcolor}
\begin{document}

\begin{tblr}{ width = \linewidth, colspec = {Q[165]Q[165]Q[165]Q[165]}, cells = {c}, row{1} = {blue!50}, row{2} = {cyan!50}, hlines, vlines} a & B & C & D \ one & two & three & noone \end{tblr}

\end{document}

sergiokapone
  • 5,578
  • 1
  • 16
  • 39
  • 1
    https://tex.stackexchange.com/questions/59227/gradient-color-in-one-cell-of-a-table?rq=1 and https://tex.stackexchange.com/questions/174998/are-there-an-easy-way-to-coloring-tables-depending-on-the-value-in-each-cell – js bibra Sep 02 '23 at 14:10

1 Answers1

3

Here is an example with {NiceTabular} of nicematrix with a row by row color gradient (you need several compilations).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{c} \CodeBefore \definecolorseries{BlueWhite}{rgb}{last}{blue}{white} \resetcolorseries[\value{iRow}]{BlueWhite} \rowlistcolors{1}{BlueWhite!!+} \Body Mathilde \ Pierre \ Paul \ Amélie \ Jacques \ Antoine \ Stéphanie \ \end{NiceTabular}

\end{document}

Output of the first code

Here is an example with a continuous gradient (Tikz must be loaded).

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

\begin{NiceTabular}{c}[color-inside] \Block[tikz = {top color=blue, bottom color=white}]{-}{} Mathilde \ Pierre \ Paul \ Amélie \ Jacques \ Antoine \ Stéphanie \ \end{NiceTabular}

\end{document}

Output of the second code

In both cases, the instructions automatically take into account the number of row and columns of the tabular.

F. Pantigny
  • 40,250