# Unusual partitioned matrix

Could anyone tell me the way the latex code producing a matrix partition whose form is the attached picture

• I couldn't solve this code? I tried many times, I reviewed all the posts but couldn't find a similar one? any help is appreciated. Thanks Commented Mar 1, 2021 at 22:56
• 'matrix' library of TikZ is a general way ctan.org/pkg/pgf Commented Mar 2, 2021 at 1:15
• Perhaps a Minimal Working Example (MWE) with what you have so far would help the community help you get the result you are seeking. Commented Mar 2, 2021 at 8:53
• Do you also need the entries or just the lines? Commented Mar 2, 2021 at 9:36
• Thank you all. It doesn't matter about the entries. I updated the picture. Commented Mar 5, 2021 at 12:54

Here is two ways of doing that with {bNiceMatrix} of nicematrix.

For the first method, I have drawn all the rules with Tikz using the PGF/Tikz nodes created by nicematrix (you need at least the version 5.11 of 2021-02-22).

For the second method, I have created blocks (with the built-in command \Block) and the key hvlines draws all the rules excepted in the blocks.

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

$\begin{bNiceMatrix}[margin] 1&2&3&4&5&6&7\\ 1&2&3&4&5&6&7\\ 1&2&3&4&5&6&7\\ 1&2&3&4&5&6&7\\ 1&2&3&4&5&6&7\\ 1&2&3&4&5&6&7\\ 1&2&3&4&5&6&7\\ \CodeAfter \tikz \foreach \x in {3,...,7} { \draw (\x-|1) -- (\x-|\inteval{\x+1}) (\x|-1) -- (\x|-\inteval{\x+1}) ; } ; \end{bNiceMatrix}$

\bigskip
$\begin{bNiceMatrix}[margin,hvlines] \Block{2-2}{}1&2&\Block{2-1}{}3&\Block{3-1}{}4&\Block{4-1}{}5&\Block{5-1}{}6&\Block{6-1}{}7\\ 1&2&3&4&5&6&7 \\ \Block{1-2}{}1&2&3&4&5&6&7 \\ \Block{1-3}{}1&2&3&4&5&6&7 \\ \Block{1-4}{}1&2&3&4&5&6&7 \\ \Block{1-5}{}1&2&3&4&5&6&7 \\ \Block{1-6}{}1&2&3&4&5&6&7 \\ \end{bNiceMatrix}$

\end{document}


You need several compilations (because nicematrix uses PGF/Tikz nodes).

• This is fascinating! unfortunately, I have tried both but it couldn't work; I got an error!! I don't know why? Would you please guide me on how to avoid that? Another issue, is I need exactly what you have done BUT without partition the leading submatrix Commented Mar 2, 2021 at 15:28
• I think you have not the latest version of nicematrix. You should update your TeX installation. If you use Overleaf, you can retrieve the latest version of that file on the SVN server of TeXLive: www.tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty and upload it in the repertory of your project in Overleaf. Commented Mar 2, 2021 at 15:32
• Indeed, I don't have nicematrix packages at all! sorry for that I didn't know about such packages. It is ok. I am very thankful for your kindness. I got it. Regards Commented Mar 2, 2021 at 15:47
• I have modified my answer in order to have an output exactly as requested. Commented Mar 2, 2021 at 15:49
• Many thanks! you are really KIND. All respect. Commented Mar 2, 2021 at 15:51

With package easybmat you can add paths to your matrix.

\documentclass{article}
\usepackage{easybmat}

\begin{document}

$P= \left[ \begin{BMAT}{ccccccc|c}{cccccc|c} 0 & 0 & 1 & 0 & 0 & 0 & 0& 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0& 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0& 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0& 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0& 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0& 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0& 0 \addpath{(0,2,4)rrrrrrr} \addpath{(0,3,4)rrrrrr} \addpath{(0,4,4)rrrrr} \addpath{(0,5,4)rrrr} \addpath{(0,6,4)rrr} \addpath{(2,7,4)dd} \addpath{(3,7,4)ddd} \addpath{(4,7,4)dddd} \addpath{(5,7,4)ddddd} \addpath{(6,7,4)dddddd} \end{BMAT} \right]$

\end{document}


• Thanks! I appreciate your assistance, Mr. Ignasi. Thank you very much Commented Mar 2, 2021 at 15:18

Off the top of my head, you could do something like:

\newcommand{\xx}{\multicolumn{1}{c}}

$\left[ \begin{array}{c|c|c|c|c|c|c} & & & & & & \\ \cline{1-2} & & & & & & \\ \cline{1-3} \xx{}& & & & & & \\ \cline{1-4} \xx{}&\xx{}& & & & &\\ \cline{1-5} Remainder left as exercise to the reader \end{array} \right]$


The \xx macro is a shortcut to reduce the amount of typing for each cell we want to drop the vertical bars in those cells that don't need them. Of course, if you don't need to fill each cell of the matrix, you could write, e.g., \multicolumn{2}{c}{} in place of \xx{}&\xx{}.

• Thanks for your help. It is inspirational Commented Mar 2, 2021 at 15:45