我尝试给矩阵的对角线着色。
\begin{equation}
C=
\begin{bmatrix}
1 & 1 & 0\\
0 & 1 & 1\\
1 & 0 & 1\\
\end{bmatrix}
\end{equation}
我发现的所有内容都与行和列有关(参见。https://tex.stackexchange.com/a/69714/74926 和 http://www.alecjacobson.com/weblog/?p=1289)有人可以帮忙吗?
我已经找到了。遗憾的是,线条覆盖了文本和括号。如果能得到进一步的帮助就太好了。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand{\tikzmark}[2]{
\tikz[overlay,remember picture,baseline]
\node[anchor=base] (#1) {$#2$};
}
\begin{document}
\[
\begin{pmatrix}
\tikzmark{top}{1} & \tikzmark{top2}{1} & 0 \\
0 & 1 & \tikzmark{bottom2}{1} \\
\tikzmark{end}{1} & 0 & \tikzmark{bottom}{1}\\
\end{pmatrix}
\]
\begin{tikzpicture}[overlay,remember picture]
\draw[red,line width=1mm,line cap=round] (top.north west) -- (bottom.south east);
\draw[red,line width=1mm,line cap=round] (top2.north west) -- (bottom2.south east);
\draw[red,line width=1mm,line cap=round] (end.north west) -- (end.south east);
\end{tikzpicture}
\end{document}
答案1
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand{\tikzmark}[2]{
\tikz[overlay,remember picture,baseline]
\node[anchor=base] (#1) {$#2$};
}
\begin{document}
\begin{equation}
\begin{pmatrix}
\tikzmark{top}{1} & \tikzmark{top2}{1} & 0 \\
0 & 1 & \tikzmark{bottom2}{1} \\
\tikzmark{end}{1} & 0 & \tikzmark{bottom}{1}\\
\end{pmatrix}
\end{equation}
\begin{tikzpicture}[overlay,remember picture]
\draw[opacity=.4,line width=3mm,line cap=round] (top.center) -- (bottom.center);
\draw[opacity=.4,line width=3mm,line cap=round] (top2.center) -- (bottom2.center);
\draw[opacity=.4,line width=3mm,line cap=round] (end.center) -- (end.center);
\end{tikzpicture}
\end{document}
答案2
欢迎使用,您可以使用如下方法:
\documentclass[a4paper]{article}
\usepackage{amsmath,amssymb,xcolor}
\newcommand\RED{\color{red}}
\begin{document}
\begin{equation}
C=
\begin{bmatrix}
\RED 1 & 1 & 0\\
0 & \RED 1 & 1\\
1 & 0 & \RED 1\\
\end{bmatrix}
\end{equation}
\end{document}
结果:
答案3
您可以使用 来实现这{pNiceMatrix}
一点nicematrix
。
\documentclass{article}
\usepackage{nicematrix,tikz}
\usepackage{tikz}
\begin{document}
\begin{equation}
\begin{pNiceMatrix}
1 & 1 & 0 \\
0 & 1 & 1 \\
1 & 0 & 1
\CodeAfter
\tikz \draw [opacity=.4,line width=3mm,line cap=round]
(1-1.center) -- (3-3.center)
(1-2.center) -- (2-3.center)
(3-1.center) -- (3-1.center) ;
\end{pNiceMatrix}
\end{equation}
\end{document}