我正在嘗試將內容發佈\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
。也可以使用 a
\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
and來完成此操作\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}