1

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:

enter image description here

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). – Henri Menke Oct 1 '17 at 1:15
  • Possible duplicate of Strike out a table cell. The accepted answer there can be trivially extended to produce the required output. – Henri Menke Oct 1 '17 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. – CarLaTeX Oct 1 '17 at 2:47
  • @CarLaTeX, that duplicate you linked still has the text split diagonally as well. – Jordan Oct 3 '17 at 20:51
  • Sorry, closing vote rectracted – CarLaTeX Oct 3 '17 at 20:54
2

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}\\
1& Read the manuals\\
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}

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.