Replies: 3 comments 1 reply
-
Not yet possible to do this, but there is already a related issue #159. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Using Tikz marks and tikz shading\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularray}
\usepackage{tikz}
\usetikzlibrary{calc}
% Andrew Stacey's code from
% http://tex.stackexchange.com/a/50054/3954
\makeatletter
\tikzset{%
remember picture with id/.style={%
remember picture,
overlay,
save picture id=#1,
},
save picture id/.code={%
\edef\pgf@temp{#1}%
\immediate\write\pgfutil@auxout{%
\noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
},
if picture id/.code args={#1#2#3}{%
\@ifundefined{save@pt@#1}{%
\pgfkeysalso{#3}%
}{
\pgfkeysalso{#2}%
}
}
}
\def\savepointas#1#2{%
\expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}
\def\tmk@labeldef#1,#2\@nil{%
\def\tmk@label{#1}%
\def\tmk@def{#2}%
}
\tikzdeclarecoordinatesystem{pic}{%
\pgfutil@in@,{#1}%
\ifpgfutil@in@%
\tmk@labeldef#1\@nil
\else
\tmk@labeldef#1,(0pt,0pt)\@nil
\fi
\@ifundefined{save@pt@\tmk@label}{%
\tikz@scan@one@point\pgfutil@firstofone\tmk@def
}{%
\pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
\pgfsys@getposition{\pgfpictureid}\save@this@pic%
\pgf@process{\pgfpointorigin\save@this@pic}%
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
\pgf@process{\pgfpointorigin\save@orig@pic}%
\advance\pgf@x by -\pgf@xa
\advance\pgf@y by -\pgf@ya
}%
}
\newcommand\tikzmark[2][]{%
\tikz[remember picture with id=#2] #1;}
\makeatother
% end of Andrew's code
\newcommand\ShadeCell[3]{%
\begin{tikzpicture}[overlay,remember picture]%
\shade[#3] ( $ (pic cs:#1) + (-6pt,10pt) $ ) rectangle ( $ (pic cs:#2) + (6pt,-6pt) $ );
\end{tikzpicture}%
}%
\begin{document}
% all n cells with shades need a separate tikzmark startn
\ShadeCell{start1}{end1}{%
shading = axis,left color=blue6,right color=magenta8,shading angle=135}
\ShadeCell{start2}{end2}{%
shading = axis,left color=red7,right color=green9,shading angle=135}
\begin{tblr}{
colspec={| l | c | c |},
cell{1}{3}={bg=magenta8},
cell{1}{2}={bg=green9},
cell{2}{1}={bg=blue6},
cell{3}{1}={bg=red7},
cell{2}{3}={preto={\tikzmark{start1}\makebox[1cm][c]\expandafter\bgroup},appto={\expandafter\egroup\tikzmark{end1}}},
cell{3}{2}={preto={\tikzmark{start2}\makebox[1cm][c]\expandafter\bgroup},appto={\expandafter\egroup\tikzmark{end2}}},
}
\hline
& A & B \\
\hline
C & & \\
\hline
D & & \\
\hline
\end{tblr}
\end{document} based on tex.stackexchange.com |
Beta Was this translation helpful? Give feedback.
0 replies
-
If you accept the limitation that every shade cell must be the widest one in its column and the highest one in its row, then you can write your code based on the existing solution in CTeX-org/forum#239 : \documentclass{article}
\usepackage{tabularray}
\usepackage{tikz}
\ExplSyntaxOn
\box_new:N \l__tblr_tikz_box
\cs_new_protected:Npn \__tblr_tikzbox_fix:n #1
{
\hbox_set:Nn \l__tblr_tikz_box {#1}
\box_set_ht:Nn \l__tblr_tikz_box { \box_ht:N \l__tblr_tikz_box - \abovesep }
\box_set_dp:Nn \l__tblr_tikz_box { \box_dp:N \l__tblr_tikz_box - \belowsep }
\box_set_wd:Nn \l__tblr_tikz_box { \box_wd:N \l__tblr_tikz_box - \rightsep }
\skip_horizontal:n { -\leftsep }
\box_use:N \l__tblr_tikz_box
}
\NewContentCommand \tikzbox [2]
{
\__tblr_tikzbox_fix:n
{
\tikz[baseline=\dim_use:N \l__tblr_strut_ht_dim + \belowsep] {#1}
#2
}
}
\ExplSyntaxOff
\NewContentCommand \shadebox [3] {%
\tikzbox{
\useasboundingbox (0,0) rectangle (2cm,1cm);
\pgfnodealias{cbb}{current bounding box}
\shade[shading = axis,left color=#1,right color=#2,shading angle=135]
(cbb.south east) rectangle (cbb.north west);
}{%
\llap{\makebox[2cm][c]{#3}}%
}%
}
\begin{document}
\begin{tblr}{
colspec={|l|c|c|}, hlines,
cell{1}{3}={bg=magenta8},
cell{1}{2}={bg=green9},
cell{2}{1}={bg=blue6},
cell{3}{1}={bg=red7},
cell{2}{3}={cmd=\shadebox{blue6}{magenta8}},
cell{3}{2}={cmd=\shadebox{red7}{green9}},
}
& A & B \\
C & & 10c \\
D & & 10c \\
\end{tblr}
\end{document} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I like the separation of cell style which tabularray offers:
How can I define the background color in cell omikron, currently
cell{4}{3} = {azure7}
, to be a gradient?Ideally, I want to have a gradient with 45 degrees rotation. I have row and column headers which each has a different background color (A and B). The cell in the table should indicate this difference by the gradient from color A to color B. See following photoshopped screenshot:
Related questions on tex.stackexchange.com
I would prefer to stick with tabularray, since it supports multi-page tables which nicematrix/tikz-matrix does not.
Simplified Solution
I would also be fine using two colors in one cell as following:
Beta Was this translation helpful? Give feedback.
All reactions