我希望矩阵的左括号有不同的颜色,但every left delimiter/.style={red}]
我只能选择将所有括号涂成相同的颜色:
\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[every left delimiter/.style={red}]
\matrix (m1) [matrix of nodes, left delimiter=[] {1 & 2\\};
\matrix (m2) [below of=m1, matrix of nodes, left delimiter=[] {1 & 2\\};
\end{tikzpicture}
\end{document}
是否可以为每个矩阵分别着色?
答案1
matrix
只是一个特殊的node
,我喜欢用最简单的 TikZ 命令编写 TikZ 代码\path
:
\documentclass[tikz,border=2pt]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\path[every left delimiter/.style={red}]
(0,0) node[matrix of math nodes,left delimiter={[}] (m1) {1 & 2\\};
\path[every left delimiter/.style={blue}]
(m1)+(1,-1) node[matrix of math nodes,left delimiter=\{] (m2) {3 & 4\\};
\path[every left delimiter/.style={orange}]
(m2)+(-.5,-1) node[matrix of math nodes,left delimiter=[] (m3) {5 & 6\\};
\end{tikzpicture}
\end{document}
答案2
我以前用过类似的东西:
\documentclass{article}
\usepackage{amsmath,xcolor,environ}
\NewEnviron{pmatrixcolor}[1][red]{%
\colorlet{currentcolor}{.}%
\mathinner{\begingroup\color{#1}\left(\color{currentcolor}%
\begin{matrix}
\BODY
\end{matrix} \color{#1}\right)\endgroup}}
\begin{document}
\[
\begin{pmatrix}
1 & 2 \\
\end{pmatrix}
\]
\[
\begin{pmatrixcolor}
1 &2 \\
\end{pmatrixcolor}
\]
\end{document}
可能会为您指明正确的方向。