\CodeAfter
我正在尝试将中的内容发布nicematrix
为背景。我通常希望得到与我们使用 获得的结果类似的结果,但具有环境\cellcolor
的灵活性tikzpicture
在上图中,我们看到C_1_1
不可见
\documentclass[amsthm]{book}
\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usepackage{nicematrix}
\NiceMatrixOptions{hvlines, rules/color=[gray]{0.95}}
\begin{document}
\begin{equation*}
\begin{bNiceMatrix}[margin]
C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}}
\\
C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}}
\\
C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}}
\CodeAfter
\begin{tikzpicture}[thick]
\draw[IndianRed1, fill=IndianRed1!11] (1-|1) rectangle (2-|2);
\end{tikzpicture}
\end{bNiceMatrix}
\end{equation*}
\end{document}
原则上,可以为 tikz 节点排版背景
\documentclass[amsthm]{book}
\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[baseline]
\node[align=flush left, inner xsep=0pt, inner ysep=1pt, outer xsep=0pt, outer ysep=0pt, anchor=base] (basmah) {text};
\begin{pgfonlayer}{background}
\fill[Ivory1, opacity=0.75] (basmah.south west) rectangle (basmah.north east);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
答案1
您有两种选择:
正如 Jasper Habicht 所建议的那样,可以将事物分开并同时使用
\CodeBefore
和\CodeAfter
。也可以使用
\Block
(当然,您必须将指令放在单元格中,也许您会认为它会使您的主数组变得混乱)。
\documentclass[amsthm]{book}
\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usepackage{nicematrix}
\NiceMatrixOptions{hvlines, rules/color=[gray]{0.95}}
\begin{document}
\begin{equation*}
\begin{bNiceMatrix}[margin]
\Block[fill=IndianRed1!11,draw = IndianRed1,line-width=1pt]{}{C_{\arabic{iRow},\arabic{jCol}}} & C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}}
\\
C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}}
\\
C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}}
\end{bNiceMatrix}
\end{equation*}
\end{document}
与往常一样nicematrix
,您需要进行多次编译。
答案2
如果你想专门用\CodeBefore
和来做这件事\CodeAfter
,这里是:
\documentclass[amsthm]{book}
\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usepackage{nicematrix}
\NiceMatrixOptions{hvlines, rules/color=[gray]{0.95}}
\begin{document}
\begin{equation*}
\begin{bNiceMatrix}[margin]
\CodeBefore
\rectanglecolor{IndianRed1!11}{1-1}{1-1}
\Body
C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}}
\\
C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}}
\\
C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}} & C_{\arabic{iRow},\arabic{jCol}}
\CodeAfter
\tikz \draw[thick,IndianRed1] (1-|1) rectangle (2-|2);
\end{bNiceMatrix}
\end{equation*}
\end{document}