答案1
由于您没有添加 MWE,我只能假设这是您所需要的:
\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}
致谢 ferahfeza和diagonal fill
风格reversed diagonal fill
。
答案2
使用{NiceTabular}
of nicematrix
。该环境类似于{tabular}
(of nicematrix
),但在单元格、行和列下创建 PGF/Tikz 节点。
因此,可以使用 Tikz 在数组的单元格下绘制任何你想要的内容。
\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}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。