4

I have the following matrix

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\begin{document}
    \begin{flalign*}
    &\bordermatrix{ & u_1 & u_2 & u_3 & \dots & u_{m-1} & u_m &v_1 & v_2 &v_3& \dots&v_{n-1}& v_n\cr
        u_1 & 5 & 8 & 1 &\dots & 1 &1 &1 &1&1&\dots &1&1 \cr
        u_2 & 2 & 0 & 1 &\dots & 1 &1 &1&1&1&\dots &1 &1\cr
        u_3 & 1 & 1 & 0 &\dots & 1 &1 &1&1&1&\dots &1 &1\cr
        \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots &\dots &  \dots &     \cr
        \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots &\dots &  \dots &     \cr
        u_{m-1} & 1 & 1 & 1 &\dots & 40 &47 &1&1&1&\dots &1&1           \cr
        u_m &   14 & 41 & 61 &\dots & 11 &10 &14&15&1   &\dots  &1&1\cr
        \\
        \hline
        \\
        v_1 &   1 & 15 & 16 &\dots & 41 &17 &0&2&2&\dots &27 &2                 \cr
        v_2 &   1 & 1 & 1 &\dots & 1 &1 &2&0&2&\dots        &2 &2           \cr
        v_3 &   1 & 1 & 1 &\dots & 1 &1 &2&2&0&\dots&2 &2                   \cr
        \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots&  \dots   \cr
        \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots&  \dots   \cr
        v_{n-1} &   1 & 1 & 1 &\dots & 1 &1 &2&2&2&\dots    &0 &2               \cr
        v_n &1 & 1 & 1 &\dots & 1 &1 &2&2&2&\dots  &2 &8                \cr
    }. \qquad
    \end{flalign*}
\end{document}

I have put a horizontal line after the mth row of the matrix. But I also want to put a vertical line after the the mth column of the matrix. I wanted the matrix to have 4 blocks.

How can I do that? Is it possible to put a vertical line after the mth column?

EDIT: I received a solution but it uses a package "nicematrix". I am getting the following error: File nicematrix.sty' not found. \renewcommand`

Can someone please give a solution without nicematrix?

2 Answers 2

1

You get the error: File nicematrix.sty not found. because your TeX distribution is not updated.
I advise you to update it.
If you can't, here is a solution with a TikZ matrix.

\documentclass[10pt,a4paper, draft]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathreplacing}
\tikzset{
    mymatr/.style={
        matrix of math nodes,
        nodes={text width=width("$\dots$"), text centered, text height=height("$1$"), 
        text depth=depth("$u_{m-1}$")},
        column 5/.style={nodes={text width=width("$u_{m-1}$"), text centered}},
        column 11/.style={nodes={text width=width("$v_{n-1}$"), text centered}}
        }
    }
\begin{document}
\begin{tikzpicture}    
\matrix[mymatr, 
  left delimiter=(,right delimiter=)]
     (m) {    
5 & 8 & 1 &\dots & 1 &1 &[6pt] 1 &1&1&\dots &1&1 \\
2 & 0 & 1 &\dots & 1 &1 &1&1&1&\dots &1 &1\\
1 & 1 & 0 &\dots & 1 &1 &1&1&1&\dots &1 &1\\
\dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots &\dots &  \dots &     \\
\dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots &\dots &  \dots &     \\
1 & 1 & 1 &\dots & 40 &47 &1&1&1&\dots &1&1           \\
14 & 41 & 61 &\dots & 11 &10 &14&15&1   &\dots  &1&1\\[30pt]
1 & 15 & 16 &\dots & 41 &17 &0&2&2&\dots &27 &2                 \\
1 & 1 & 1 &\dots & 1 &1 &2&0&2&\dots        &2 &2           \\
1 & 1 & 1 &\dots & 1 &1 &2&2&0&\dots&2 &2                   \\
\dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots&  \dots   \\
\dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots&  \dots   \\
1 & 1 & 1 &\dots & 1 &1 &2&2&2&\dots    &0 &2               \\
1 & 1 & 1 &\dots & 1 &1 &2&2&2&\dots  &2 &8                \\
};
\matrix[mymatr, anchor=south west,
        ] at (m.north west) 
{u_1 & u_2 & u_3 & \dots & u_{m-1} & u_m &[6pt] v_1 & v_2 &v_3& \dots&v_{n-1}& v_n\\};
\matrix[mymatr, anchor=north east, column 1/.style={nodes={text width=width("$u_{m-1}$"), text centered}},
xshift=-6pt] at (m.north west) {
u_1\\   
u_2 \\  
u_3 \\  
\dots \\    
\dots   \\
u_{m-1}\\
u_m     \\[30pt]
v_1     \\
v_2     \\
v_3     \\
\dots   \\
\dots   \\
v_{n-1}\\
v_n     \\};
\draw ([xshift=-6pt]m.west) -- ([xshift=6pt]m.east);
\draw ([xshift=2pt]m.north) -- ([xshift=2pt]m.south);
\end{tikzpicture}
\end{document}

enter image description here

1

Here is a solution with {pNiceArray} of nicematrix.

\documentclass[10pt,a4paper]{article}
\usepackage{nicematrix}

\begin{document}

\begin{flalign*}
\setcounter{MaxMatrixCols}{15}
\begin{pNiceArray}[first-row,first-col]{cccccc|cccccc}
    & u_1 & u_2 & u_3 & \dots & u_{m-1} & u_m &v_1 & v_2 &v_3& \dots&v_{n-1}& v_n\\
u_1 & 5 & 8 & 1 &\dots & 1 &1 &1 &1&1&\dots &1&1 \\
u_2 & 2 & 0 & 1 &\dots & 1 &1 &1&1&1&\dots &1 &1\\
u_3 & 1 & 1 & 0 &\dots & 1 &1 &1&1&1&\dots &1 &1\\
\dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots &\dots &  \dots \\
\dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots &\dots &  \dots \\
u_{m-1} & 1 & 1 & 1 &\dots & 40 &47 &1&1&1&\dots &1&1 \\
u_m &   14 & 41 & 61 &\dots & 11 &10 &14&15&1   &\dots  &1&1\\
\\
\hline
\\
v_1 &   1 & 15 & 16 &\dots & 41 &17 &0&2&2&\dots &27 &2 \\
v_2 &   1 & 1 & 1 &\dots & 1 &1 &2&0&2&\dots &2 &2 \\
v_3 &   1 & 1 & 1 &\dots & 1 &1 &2&2&0&\dots&2 &2 \\
\dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots&  \dots   \\
\dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots&  \dots   \\
v_{n-1} &   1 & 1 & 1 &\dots & 1 &1 &2&2&2&\dots  &0 &2 \\
v_n &1 & 1 & 1 &\dots & 1 &1 &2&2&2&\dots  &2 &8 \\
\end{pNiceArray}
\end{flalign*}

\end{document}

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

Output of the above code

5
  • Nice answer (+1), to my taste I would add option margin (that horizontal line doesn't touch parenthesis.
    – Zarko
    Jan 27, 2022 at 16:03
  • I am getting the following error:File `nicematrix.sty' not found. \renewcommand; Can you please do it without nicematrix
    – Charlotte
    Jan 28, 2022 at 6:05
  • nicematrix is in all classical LaTeX distributions: MikTeX, TexLive, MacTeX,... Jan 28, 2022 at 6:19
  • So how can I fix it? Can you help please
    – Charlotte
    Jan 28, 2022 at 8:18
  • On Windows, usually, people use MiKTeX. In that case, you may use the programme "MiKTeX Console" to install new packages. If you use TeXLive or MacTeX, you should the command tlmgr: sudo tlmgr install nicematrix. Jan 28, 2022 at 12:01

You must log in to answer this question.

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