3

Consider the following matrix : enter image description here

I have no problem in constructing the matrix and I have no problem in circling the first and the fifth row, but I have no idea how to insert these arrows outside this matrix. I hope someone can help me out.

Here is what I wrote :

\documentclass[12pt,english]{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\usepackage{nicematrix}
\begin{document}
$$
\begin{bNiceMatrix}%
[code-after = { \tikz \node [draw, rounded corners, fit = (5-1) (5-7)] { };  \tikz \node [draw, rounded corners, fit = (1-1) (1-7)] { } ;},  left-margin = 7pt, right-margin = 7pt] 
 0 & 0 & 0 & 0 & 1 & \cdots & 0 \\
 0 & 1 & 0 & 0 & 0 & \cdots & 0 \\
0 & 0 & \ddots & 0 & 0 & \cdots & 0 \\
0 & 0 & 0 & 1 & 0 & \cdots & 0 \\
1 & 0 & 0 & 0 & 0 & \cdots & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 1
\end{bNiceMatrix}
$$
\end{document}
egreg
  • 1,121,712

2 Answers2

2

Use last-col:

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\usepackage{nicematrix}

\begin{document}

[ \begin{bNiceMatrix}[ code-after = { \tikz \node [draw, rounded corners, fit = (5-1) (5-7)] { }; \tikz \node [draw, rounded corners, fit = (1-1) (1-7)] { } ; }, left-margin = 7pt, right-margin = 7pt, last-col, ] 0 & 0 & 0 & 0 & 1 & \cdots & 0 & \leftarrow 1\ 0 & 1 & 0 & 0 & 0 & \cdots & 0 & \leftarrow 2\ 0 & 0 & \smash{\ddots} & 0 & 0 & \cdots & 0 & \smash{\vdots} \ 0 & 0 & 0 & 1 & 0 & \cdots & 0 & \leftarrow i_1-1 \ 1 & 0 & 0 & 0 & 0 & \cdots & 0 & \leftarrow i_1 \ 0 & 0 & 0 & 0 & 0 & 1 & 0 & \smash{\vdots} \ 0 & 0 & 0 & 0 & 0 & 0 & 1 & \leftarrow n \end{bNiceMatrix} ]

\end{document}

enter image description here

egreg
  • 1,121,712
1

You wrote,

my concern is how to add the arrows on the right of the matrix.

Your objective may be achieved easily by adding a one-column, left-aligned array environment.

enter image description here

\documentclass[12pt,english]{article}
\usepackage{amsmath}
\usepackage{old-arrows} % optional (for smaller arrowheads)
\begin{document}
\[
\begin{bmatrix}
0 & 0 & 0 & 0 & 1 & \cdots & 0 \\
0 & 1 & 0 & 0 & 0 & \cdots & 0 \\
0 & 0 & \smash{\ddots} & 0 & 0 & \cdots & 0 \\
0 & 0 & 0 & 1 & 0 & \cdots & 0 \\
1 & 0 & 0 & 0 & 0 & \cdots & 0 \\
0 & 0 & 0 & 0 & 0 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 1
\end{bmatrix}
\begin{array}{l}
\gets 1 \\
\gets 2 \\
\smash{\vdots} \\
\gets i_1-1 \\
\gets i_1 \\
\smash{\vdots} \\
\gets n
\end{array}
\]
\end{document}
Mico
  • 506,678