4
\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,amssymb,amsthm}
\begin{document}
\[A=
\begin{pmatrix}
I       &0 &\ldots  &0\\
0 & I      &\ddots  &\vdots\\
\vdots  &\ddots  &I       &0\\
0 &\ldots  &0 &I
\end{pmatrix}
\]

and 
\[
B=\begin{pmatrix}
0 &\cdots &0& I\\
\vdots &0&I&0\\
\vdots & \vdots &  & \vdots\\
I & 0 &\cdots& 0\\
\end{pmatrix}
\]
\end{document}

I want to draw the following two matrices in this way.

enter image description here

  • 2
    I suggest nicematrix package. – Sebastiano Mar 25 at 18:32
  • Can I draw $B$ like my attempt in my question without using nicematrix package? – Schüler Mar 25 at 19:10
  • Yes, it's certainly possible. Some packages are also built to shorten time and make the code easier and more efficient. – Sebastiano Mar 25 at 19:30
5

Here is a proposal using the nicematrix package. Unfortunately, as far as I could see, their nice dotted lines are not in some styles that can be used by the user for their own annotations, so I had to redo it using a variant of this answer.

\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,amssymb,amsthm}
\usepackage{nicematrix}
\tikzset{Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
    line width=1pt,
    dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
    shorten >=0.3em,shorten <=0.3em},
    Dotted/.default=5}
\begin{document}
\[A=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (2-2) -- (3-3);
\end{tikzpicture}}]%
I       &0 &\Cdots  &0\\
0 & I      &\Ddots  &\Vdots\\
\Vdots  &\Ddots  &I       &0\\
0 &\Cdots  &0 &I
\end{pNiceArray}
\]
and 
\[B=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (3-2) -- (2-3);
\draw[Dotted] (3-1) -- (1-3);
\draw[Dotted] (4-2) -- (2-4);
\end{tikzpicture}}]%
0       &\Cdots  &0 &I\\
\Vdots &       &I  &0\\
0  &I  &       &\Vdots\\
I &0  &\Cdots &0
\end{pNiceArray}
\]
\end{document}

enter image description here

Or a version with parallel dotted lines.

\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,amssymb,amsthm}
\usepackage{nicematrix}
\tikzset{Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
    line width=1pt,
    dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
    shorten >=0.3em,shorten <=0.3em},
    Dotted/.default=5}
\begin{document}
\[A=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (2-2) -- (3-3);
\end{tikzpicture}}]%
I       &0 &\Cdots  &0\\
0 & I      &\Ddots  &\Vdots\\
\Vdots  &\Ddots  &I       &0\\
0 &\Cdots  &0 &I
\end{pNiceArray}
\]
and 
\[B=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (3-2.30) -- (2-3.-150);
\draw[Dotted] (3-1) -- (1-3);
\draw[Dotted] (4-2) -- (2-4);
\end{tikzpicture}}]%
0       &\Cdots  &0 &I\\
\Vdots &       &I  &0\\
0  &I  &       &\Vdots\\
I &0  &\Cdots &0
\end{pNiceArray}
\]
\end{document}

Or without nicematrix.

\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,mathdots}
\begin{document}
\[A=
\begin{pmatrix}
I       &0 &\cdots  &0\\
0 & I \smash{\makebox[0pt][l]{\;\raisebox{-0.8em}{$\ddots$}}}     &\ddots  &\vdots\\
\vdots  &\ddots  &I       &0\\
0 &\cdots  &0 &I
\end{pmatrix}
\]
and 
\[B=
\begin{pmatrix}
0       &\cdots  &0 &I\\
\vdots &  \iddots     &I  &0\\
0  &I\smash{\makebox[0pt][l]{\;\raisebox{0.8em}{$\iddots$}}}  &  \iddots      &\vdots\\
I &0  &\cdots &0
\end{pmatrix}
\]

\end{document}

enter image description here

|improve this answer|||||
  • Isn't it possible to ensure all diagonal dots be parallel in matrix B? – Bernard Mar 25 at 18:54
  • Great! :-) ....my approvation. – Sebastiano Mar 25 at 18:54
  • @Bernard Sure. This is rather easy and can be achieved in (at least) two ways: (i) increase the distance between the rows or (ii) change the anchors at which the dotted line between the I's attaches to the nodes. I do not know which one the OP prefers. – Schrödinger's cat Mar 25 at 18:59
  • Is it possible to draw without nicematrix? – Schüler Mar 25 at 19:00
  • @Schrödinger'scat I just want to simple presentation because I want to add this form in my research paper. Thanks a lot. For the matrix $A$ in my question I don't use nicematrix. Can I drw $B$ by simalar way as in my question? – Schüler Mar 25 at 19:03
3

This is an adaptation of the answer of Schrödinger's cat. In fact, since a recent version of nicematrix (3.13 2020-03-15), it's possible to draw the continuous dotted lines with any line style provided by Tikz.

Remark: Starting with this version 3.13, nicematrix doesn't load tikz any longer. It only loads pgf (because, by default, this new version only uses pgf).

\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,amssymb,amsthm}
\usepackage{nicematrix}

\usepackage{tikz}

\tikzset{Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
    line width=1pt,
    dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
    shorten >=0.3em,shorten <=0.3em},
    Dotted/.default=5}


\begin{document}

\begin{gather*}
A=
\begin{pNiceArray}{CCCC}[code-after={\line[line-style = Dotted]{2-2}{3-3}}]
I       & 0      & \Cdots  &0     \\
0       & I      & \Ddots  &\Vdots\\
\Vdots  &\Ddots  & I       &0     \\
0       &\Cdots  & 0       &I
\end{pNiceArray}
\\
B=
\begin{pNiceArray}{CCCC}[
code-after = {
\line[line-style = Dotted]{3-2}{2-3} }
]%
0      & \Cdots  & 0     & I\\
\Vdots & \Iddots[line-style=Dotted] & I     & 0\\
0      & I       & \Iddots[line-style=Dotted] & \Vdots\\
I      & 0       &\Cdots & 0
\end{pNiceArray}
\end{gather*}


\end{document}

Result of the above code

|improve this answer|||||
  • 1
    Good to know about pgf, but how to know, when tikz is needed. So far i see, that is neded in the most of cases, so why tikz is excluded t load of nicematrix is a mystery for me :-) nice answer, +1 – Zarko Mar 25 at 20:24
  • tikz is only required when the new option line-style is used with another value than standard (the initial value). In such a circonstance, if tikz is not loaded, a message is issued (and the option line-style is ignored). – F. Pantigny Mar 25 at 20:28
  • @F.Pantigny i have finished my votes....:-( – Sebastiano Mar 25 at 22:40
  • 1
    I have not forgot...and excuse me very much for my delay. – Sebastiano Mar 29 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.