1

I have taken this code from the documentation of nicematrix package to the pag. 44/208 version 5.12 of at the date of 2021/03/10.

enter image description here

  1. In the meantime I have this error of compilation: why? (I have the recent updating MikTeX on OS W7-32bit).

    \documentclass[a4paper,12pt]{article} \usepackage{nicematrix,tikz} \begin{document} $\begin{pNiceMatrix}[margin,create-medium-nodes] \Block{3-3}<\Large>{A} & & & 0 \\ & \hspace*{1cm} & & \Vdots \\ & & & 0 \\ 0 & \Cdots& 0 & 0 \CodeAfter \tikz \node [highlight = (1-1-block-medium)] {} ; \end{pNiceMatrix}$ \end{document} 

    ! Package pgfkeys Error: I do not know the key '/tikz/highlight', to which you passed '(1-1-block-medium)', and I am going to ignore it. Perhaps you misspelled it. See the pgfkeys package documentation for explanation. Type H for immediate help. ...
    l.12 \end{pNiceMatrix} $ ?

  2. If I had to draw a matrix with four boxed rectangles or squares where inside are the elements of the matrix. Is it possible?

enter image description here

1 Answer 1

2

The key highlight is defined previously in the document (documentation of nicematrix).


For the construction you want, consider first the following matrix.

\documentclass{standalone} \usepackage{nicematrix} \begin{document} \(\begin{pNiceArray}{cc|cc} \frac{(a^2+b^2)^2}{A^2+B^2} & \frac{2ab}{a+b} & A^2+B^2 & \frac{a^2+b^2}{2} \\ 0 & \frac{a^2+b^2}{2} & \frac{(a^2+b^2)^2}{A^2+B^2} & \frac{2ab}{a+b} \\ \hline 2A^2+2B^2 & 0 & \frac{2ab}{a+b} & \frac{(a^2+b^2)^2}{A^2+B^2} \\ \frac{2ab}{a+b} & \frac{(a^2+b^2)^2}{A^2+B^2} & 0 & \frac{a^2+b^2}{2} \\ \end{pNiceArray}\) \end{document} 

First matrix

Before drawing frames, you have to add space. For the vertical space, I use some \vskip in \noalign.

\documentclass{standalone} \usepackage{nicematrix} \begin{document} $\begin{pNiceArray}{cc|cc}[margin=2pt] \noalign{\vskip\smallskipamount} \frac{(a^2+b^2)^2}{A^2+B^2} & \frac{2ab}{a+b} & A^2+B^2 & \frac{a^2+b^2}{2} \\ 0 & \frac{a^2+b^2}{2} & \frac{(a^2+b^2)^2}{A^2+B^2} & \frac{2ab}{a+b} \\[4pt] \hline \noalign{\vskip4pt} 2A^2+2B^2 & 0 & \frac{2ab}{a+b} & \frac{(a^2+b^2)^2}{A^2+B^2} \\ \frac{2ab}{a+b} & \frac{(a^2+b^2)^2}{A^2+B^2} & 0 & \frac{a^2+b^2}{2} \\ \noalign{\vskip\smallskipamount} \end{pNiceArray}$ \end{document} 

Second matrix

You can now draw the frames with Tikz in the \CodeAfter.

\documentclass{standalone} \usepackage{nicematrix,tikz} \usetikzlibrary{fit} \begin{document} \tikzset{highlight/.style={rectangle, draw=blue, rounded corners = 0.5 mm, inner sep=1pt, fit=#1}} $\begin{pNiceArray}{cc|cc}[margin=2pt] \noalign{\vskip\smallskipamount} \frac{(a^2+b^2)^2}{A^2+B^2} & \frac{2ab}{a+b} & A^2+B^2 & \frac{a^2+b^2}{2} \\ 0 & \frac{a^2+b^2}{2} & \frac{(a^2+b^2)^2}{A^2+B^2} & \frac{2ab}{a+b} \\[4pt] \hline \noalign{\vskip4pt} 2A^2+2B^2 & 0 & \frac{2ab}{a+b} & \frac{(a^2+b^2)^2}{A^2+B^2} \\ \frac{2ab}{a+b} & \frac{(a^2+b^2)^2}{A^2+B^2} & 0 & \frac{a^2+b^2}{2} \\ \noalign{\vskip\smallskipamount} \CodeAfter \begin{tikzpicture} \node [highlight=(1-1)(1-2)(2-1)(2-2)] {} ; \node [highlight=(1-3)(1-4)(2-3)(2-4)] {} ; \node [highlight=(3-1)(3-2)(4-1)(4-2)] {} ; \node [highlight=(3-3)(3-4)(4-3)(4-4)] {} ; \end{tikzpicture} \end{pNiceArray}$ \end{document} 

Third matrix

Maybe you want homogeneity for the four blue frames. In that case, you should use the medium nodes (created by nicematrix).

\documentclass{standalone} \usepackage{nicematrix,tikz} \usetikzlibrary{fit} \begin{document} \tikzset{highlight/.style={rectangle, draw=blue, rounded corners = 0.5 mm, inner sep=1pt, fit=#1}} $\begin{pNiceArray}{cc|cc}[margin=2pt,create-medium-nodes] \noalign{\vskip\smallskipamount} \frac{(a^2+b^2)^2}{A^2+B^2} & \frac{2ab}{a+b} & A^2+B^2 & \frac{a^2+b^2}{2} \\ 0 & \frac{a^2+b^2}{2} & \frac{(a^2+b^2)^2}{A^2+B^2} & \frac{2ab}{a+b} \\[4pt] \hline \noalign{\vskip4pt} 2A^2+2B^2 & 0 & \frac{2ab}{a+b} & \frac{(a^2+b^2)^2}{A^2+B^2} \\ \frac{2ab}{a+b} & \frac{(a^2+b^2)^2}{A^2+B^2} & 0 & \frac{a^2+b^2}{2} \\ \noalign{\vskip\smallskipamount} \CodeAfter \begin{tikzpicture}[name suffix = -medium] \node [highlight=(1-1)(1-2)(2-1)(2-2)] {} ; \node [highlight=(1-3)(1-4)(2-3)(2-4)] {} ; \node [highlight=(3-1)(3-2)(4-1)(4-2)] {} ; \node [highlight=(3-3)(3-4)(4-3)(4-4)] {} ; \end{tikzpicture} \end{pNiceArray}$ \end{document} 

Fourth matrix

1
  • Thank you very very very much for your exhaustive explanation and for your precious contribute. Commented Mar 26, 2021 at 21:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.