3

I was wondering how I could create this matrix in LaTeX:

enter image description here

I know how to do the matrix part but my question is the lines, how can I make them stop in (1,1), (2,2) and (3,3)?

2
  • 2
    I'd give nicematrix a try, since it is build using tikz this should not be a problem.
    – daleif
    May 31 at 11:50
  • 3
    It would help people if you could edit into your question some code that produces the parts you know how to do, it is fine if you don't know how to add the colour lines (that's what this site is for) but it helps people help you when there is a starting point beginning with \documentclass{...} and ending with \end{document}
    – JamesT
    May 31 at 12:06

1 Answer 1

4

Here is a possibility with nicematrix and tikz.

enter image description here

\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}
3
  • 1
    Thanks, this is wonderful !!!
    – Ravinala
    May 31 at 12:15
  • And how did it make it look squared, before my matrix was more of a rectangle, i think it is related to NIceMatrix i will have a look
    – Ravinala
    May 31 at 12:20
  • \NiceMatrixOptions{cell-space-limits = 2pt} adjusts vertical space between rows.
    – Sandy G
    May 31 at 12:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .