矩阵中的彩色半线

矩阵中的彩色半线

我想知道如何在 LaTeX 中创建这个矩阵:

在此处输入图片描述

我知道如何做矩阵部分,但我的问题是线条,我怎样才能让它们停在(1,1),(2,2)和(3,3)?

答案1

nicematrix这是和的可能性tikz

在此处输入图片描述

\documentclass{article}

\usepackage{nicematrix, tikz}

\begin{document}

\[
\NiceMatrixOptions{cell-space-limits = 2pt}
\begin{pNiceMatrix}[first-col]
\color{red}\Delta_1 & \frac{\partial^2f}{\partial x_1^2} & \frac{\partial^2f}{\partial x_1^2} & \frac{\partial^2f}{\partial x_1^2}\\
\color{green}\Delta_2 & \frac{\partial^2f}{\partial x_1^2} & \frac{\partial^2f}{\partial x_1^2} & \frac{\partial^2f}{\partial x_1^2}\\
\color{blue}\Delta_3 & \frac{\partial^2f}{\partial x_1^2} & \frac{\partial^2f}{\partial x_1^2} & \frac{\partial^2f}{\partial x_1^2}
\CodeAfter
\tikz{
    \draw[red, shorten >=-3mm] (1-|2) -- (2-|2) -- (2-|1);
    \draw[green, shorten >=-3mm] (1-|3) -- (3-|3) -- (3-|1);
    \draw[blue, shorten >=-3mm] (1-|4) -- (4-|4) -- (4-|1);
}
\end{pNiceMatrix}
\]

\end{document}

相关内容