有没有比这个更好的方法来绘制连续的锯齿形对角线?
我的代码:
\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{fullpage,amsmath}
\usepackage{times}
\begin{document}
\begin{tikzpicture}[baseline=(A.center)]
\tikzset{BarreStyle/.style = {opacity=.3,line width=3 mm,line cap=round,color=#1}}
\matrix(A) [matrix of math nodes, left delimiter = {[}, right delimiter ={]}]
{ M_{11} &|[color = blue]| M_{12} & M_{13} &|[color = magenta]| M_{14} & M_{15} &|[color = red]| M_{16} \\
|[color = blue]|M_{21} & M_{22} & |[color = magenta]|M_{23} & M_{24} & |[color = red]|M_{25} & M_{26} \\
M_{31} & |[color = magenta]|M_{32} & M_{33} &|[color = red]| M_{34} & M_{35} &|[color = orange]| M_{36} \\
|[color = magenta]| M_{41} & M_{42} &|[color = red]| M_{43} & M_{44} &|[color = orange]| M_{45} & M_{46} \\
M_{51} & |[color = red]|M_{52} & M_{53} & |[color = orange]|M_{54} & M_{55} &|[color = olive]| M_{56} \\
|[color = red]|M_{61} & M_{62} &|[color = orange]| M_{63} & M_{64} &|[color = olive]| M_{65} & M_{66} \\
};
\draw [BarreStyle=red] (A-1-1.west) to (A-1-2.east);
\draw [BarreStyle=red] (A-1-2.north) to (A-2-2.south);
\draw [BarreStyle=red] (A-2-2.west) to (A-2-3.east);
\draw [BarreStyle=red] (A-2-3.north) to (A-3-3.south);
\draw [BarreStyle=red] (A-3-3.west) to (A-3-4.east);
\draw [BarreStyle=red] (A-3-4.north) to (A-4-4.south);
\draw [BarreStyle=red] (A-4-4.west) to (A-4-5.east);
\draw [BarreStyle=red] (A-4-5.north) to (A-5-5.south);
\draw [BarreStyle=red] (A-5-5.west) to (A-5-6.east);
\draw [BarreStyle=red] (A-5-6.north) to (A-6-6.south);
\end{tikzpicture}
\end{document}
答案1
可能吧……
\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{fullpage,amsmath}
\usepackage{times}
\begin{document}
\begin{tikzpicture}[baseline=(A.center)]
\tikzset{BarreStyle/.style = {opacity=.3,line width=3 mm,line cap=round,color=#1}}
\matrix(A) [matrix of math nodes, left delimiter = {[}, right delimiter ={]}]
{ M_{11} &|[color = blue]| M_{12} & M_{13} &|[color = magenta]| M_{14} & M_{15} &|[color = red]| M_{16} \\
|[color = blue]|M_{21} & M_{22} & |[color = magenta]|M_{23} & M_{24} & |[color = red]|M_{25} & M_{26} \\
M_{31} & |[color = magenta]|M_{32} & M_{33} &|[color = red]| M_{34} & M_{35} &|[color = orange]| M_{36} \\
|[color = magenta]| M_{41} & M_{42} &|[color = red]| M_{43} & M_{44} &|[color = orange]| M_{45} & M_{46} \\
M_{51} & |[color = red]|M_{52} & M_{53} & |[color = orange]|M_{54} & M_{55} &|[color = olive]| M_{56} \\
|[color = red]|M_{61} & M_{62} &|[color = orange]| M_{63} & M_{64} &|[color = olive]| M_{65} & M_{66} \\
};
\path [fill=red, fill opacity=0.25,rounded corners=0.125cm]
(A-1-1.north west) \foreach \i in {1,...,6}{ |- (A-\i-\i.south east) }
\foreach \i in {5,...,1} { |- (A-\i-\i.north east) } -- cycle;
\end{tikzpicture}
\end{document}
答案2
那这个呢?
代码(仅更改的部分):
\tikzset{BarreStyle/.style = {
opacity=.3,line width=6 mm,
line cap=round, line join=round,
color=#1, shorten >= -0.1ex, shorten <= -1ex}
}
[Same matrix definition]
\draw [BarreStyle=red] (A-1-1.center) to (A-1-2.center)
to (A-2-2.center)
to (A-2-3.center)
to (A-3-3.center)
to (A-3-4.center)
to (A-4-4.center)
to (A-4-5.center)
to (A-5-5.center)
to (A-5-6.center)
to (A-6-6.center);
答案3
与。{pNiceMatrix}
nicematrix
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
\renewcommand{\arraystretch}{1.4}
\setlength{\arraycolsep}{8pt}
$\begin{bNiceMatrix}[margin]
\CodeBefore
\tikz \fill [red!10,rounded corners]
(1-|1) |- (2-|2) |- (3-|3) |- (4-|4) |- (5-|5) |- (6-|6) |- (7-|7)
|- (5-|6) |- (4-|5) |- (3-|4) |- (2-|3) |- (1-|2) -- cycle ;
\Body
M_{11} &\color{blue} M_{12} & M_{13} &\color{magenta} M_{14} & M_{15} &\color{red} M_{16} \\
\color{blue}M_{21} & M_{22} & \color{magenta}M_{23} & M_{24} & \color{red}M_{25} & M_{26} \\
M_{31} & \color{magenta}M_{32} & M_{33} &\color{red} M_{34} & M_{35} &\color{orange} M_{36} \\
\color{magenta} M_{41} & M_{42} &\color{red} M_{43} & M_{44} &\color{orange} M_{45} & M_{46} \\
M_{51} & \color{red}M_{52} & M_{53} & \color{orange}M_{54} & M_{55} &\color{olive} M_{56} \\
\color{red}M_{61} & M_{62} &\color{orange} M_{63} & M_{64} &\color{olive} M_{65} & M_{66}
\end{bNiceMatrix}$
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。