# LaTeX table non-split cell with diagonal split colour

Kind of a weird circumstance, but I have a table cell where I need the text to be in the cell normally (non-split) and the cell colour to be split diagonally.

I know how to use slashbox to split the cell, but there doesn't seem to be any way to split the colour without also splitting the text. Basically, I need it to look like this:

Any suggestions would be greatly appreciated.

• Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See minimal working example (MWE). Oct 1, 2017 at 1:15
• Possible duplicate of Strike out a table cell. The accepted answer there can be trivially extended to produce the required output. Oct 1, 2017 at 1:17
• @HenriMenke The OP says ". I know how to use slashbox to split the cell, but there doesn't seem to be any way to split the colour without also splitting the text." I don't think the correct duplicate is the one you indicated. Oct 1, 2017 at 2:47
• @CarLaTeX, that duplicate you linked still has the text split diagonally as well. Oct 3, 2017 at 20:51
• Sorry, closing vote rectracted Oct 3, 2017 at 20:54

Since you didn't add an MWE, I can only suppose this is what you need:

\documentclass{article}
\usepackage{makecell}
\usepackage{tikz}
\usetikzlibrary{matrix}
% code (slightly modified) from https://tex.stackexchange.com/a/343392/101651
\tikzset{
diagonal fill/.style 2 args={fill=#2, path picture={%
\fill[#1] (path picture bounding box.south west) -|
(path picture bounding box.north east) -- cycle;}},
reversed diagonal fill/.style 2 args={fill=#2, path picture={
\fill[#1] (path picture bounding box.north west) |-
(path picture bounding box.south east) -- cycle;}}
}

\begin{document}
\begin{table}
\centering
\begin{tikzpicture}
\matrix[matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
column 2/.style={nodes={text width=4.5cm}},
row 1/.style={nodes={minimum height=7ex}},
align=center,
text centered,
nodes={text width=2cm,
text height=1.5ex,
text depth=.25ex,
minimum height=4ex,
}] (mymatr) {
|[reversed diagonal fill={green}{red}]|\makecell{Let's\\recap} & \makecell{Van Duck's \\rules}\\
2& Look at the log\\
3& Search on \TeX.SE\\
4& |[diagonal fill={yellow}{orange}]|\color{blue}\bfseries Always add an MWE\\
};
\draw[thick] (mymatr-1-1.north west) -- (mymatr-1-2.north east);
\draw (mymatr-1-1.south west) -- (mymatr-1-2.south east);
\draw[thick] (mymatr-5-1.south west) -- (mymatr-5-2.south east);
\end{tikzpicture}
\end{table}
\end{document}


Credits to ferahfeza for the diagonal fill and reversed diagonal fill styles.

With {NiceTabular} of nicematrix. That environment is similar to {tabular} (of nicematrix) but creates PGF/Tikz nodes under the cells, rows and columns.

Thus, it's possible to use Tikz to draw whatever you want under the cells of the array.

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

\begin{document}

\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular}{ccc}
\CodeBefore
\begin{tikzpicture}
\fill [red!15] (1-|1) -- (2-|1) -- (2-|2) -- cycle ;
\fill [blue!15] (1-|1) -- (1-|2) -- (2-|2) -- cycle ;
\end{tikzpicture}
\Body
Some text & other text & another text \\
Some text & other text & another text \\
Some text & other text & another text \\
\end{NiceTabular}

\bigskip
\begin{NiceTabular}{ccc}[hvlines]
\CodeBefore
\begin{tikzpicture}
\fill [red!15] (1-|1) -- (2-|1) -- (2-|2) -- cycle ;
\fill [blue!15] (1-|1) -- (1-|2) -- (2-|2) -- cycle ;
\end{tikzpicture}
\Body
Some text & other text & another text \\
Some text & other text & another text \\
Some text & other text & another text \\
\end{NiceTabular}

\end{document}


You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).