20

How do I display truly diagonal matrices? I want to have a diagonal bloc matrix. The solution below has several problems : the diagonal terms aren't really aligned in the first half, and the diagonal dots \ddots aren't steep enough between the zeros in the second half.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
    \mathrm{Mat}(u;\mathcal{B})=
    \begin{pmatrix}
        I_{n_+}\\&-I_{n_-}\\
        &&R_{\theta_1}\\
        &&&R_{\theta_2}\\
        &&&&\ddots\\
        &&&&&R_{\theta_r}\\
        &&&&&&0\\
        &&&&&&&0\\
        &&&&&&&&\ddots\\
        &&&&&&&&&0\\
    \end{pmatrix}
\]
\end{document}
2
  • 1
    @Sebastiano Please never ever remove such spaces, this will bereave us of any possibility to revert the \\ corruption !!!!! May 27, 2017 at 21:12
  • @samcarter Ok. I like the order and I thought that eliminating the spaces does not affect the correct compilation.
    – Sebastiano
    May 29, 2017 at 6:12

6 Answers 6

20

Maybe this?

\documentclass{article}
\usepackage{amsmath,mathtools}
\DeclareMathOperator{\Mat}{Mat}
\newcommand{\diagentry}[1]{\mathmakebox[1.8em]{#1}}
\newcommand{\xddots}{%
  \raise 4pt \hbox {.}
  \mkern 6mu
  \raise 1pt \hbox {.}
  \mkern 6mu
  \raise -2pt \hbox {.}
}
\begin{document}
\[
\Mat(u;\mathcal{B})=
\begin{pmatrix}
    \diagentry{I_{n_+}}\\
    &\diagentry{-I_{n_-}}\\
    &&\diagentry{R_{\theta_1}}\\
    &&&\diagentry{R_{\theta_2}}\\
    &&&&\diagentry{\xddots}\\
    &&&&&\diagentry{R_{\theta_r}}\\
    &&&&&&\diagentry{0}\\
    &&&&&&&\diagentry{0}\\
    &&&&&&&&\diagentry{\xddots}\\
    &&&&&&&&&\diagentry{0}\\
\end{pmatrix}
\]
\end{document}

enter image description here

14

another one that puts the burden on the reader but saves his/her eyes in my opinion

\documentclass{article}
\usepackage{mathtools}
\DeclareMathOperator{\Mat}{Mat}
\DeclarePairedDelimiter{\diagfences}{(}{)}
\newcommand{\diag}{\operatorname{diag}\diagfences}
\begin{document}\noindent
I would instead do either 
\[
\Mat(u;\mathcal{B})=
\begin{pmatrix}
I_{n_+}\\
&\!\!-I_{n_-}\\
&&R_{\theta}\\
&&&0_m
\end{pmatrix},\;R_{\theta}=\diag{R_{\theta_1}, \cdots,R_{\theta_r}}
\]
or even
\[
\Mat(u;\mathcal{B})= \diag{I_{n_+},-I_{n_-},R_{\theta},0_m},\; R_{\theta}=\diag{R_{\theta_1}\, ,\, \cdots,R_{\theta_r}}
\]

\end{document}

enter image description here

13

enter image description here

One possibility is to assert control and position the items at exactly a 45 degree slope (or whatever slope you want) by adjusting the coordinates:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\mathrm{Mat}(u;\mathcal{B})=
\begin{pmatrix}
I_{n_+}\\&-I_{n_-}\\
&&R_{\theta_1}\\
&&&R_{\theta_2}\\
&&&&\ddots\\
&&&&&R_{\theta_r}\\
&&&&&&0\\
&&&&&&&0\\
&&&&&&&&\ddots\\
&&&&&&&&&0\\
\end{pmatrix}
\]

\[\setlength\unitlength{13pt}
\mathrm{Mat}(u;\mathcal{B})=
\left(\begin{picture}(11,6)(0,-5.5)
\put(1,-1){\makebox(0,0){$I_{n_+}$}}
\put(2,-2){\makebox(0,0){$-I_{n_-}$}}
\put(3,-3){\makebox(0,0){$R_{\theta_1}$}}
\put(4,-4){\makebox(0,0){$R_{\theta_2}$}}
%\put(5,-5){\makebox(0,0){$\ddots$}}
\put(4.8,-4.8){\makebox(0,0){$\cdot$}}
\put(5.1,-5.1){\makebox(0,0){$\cdot$}}
\put(5.4,-5.4){\makebox(0,0){$\cdot$}}
\put(6,-6){\makebox(0,0){$R_{\theta_r}$}}
\put(7,-7){\makebox(0,0){$0$}}
\put(8,-8){\makebox(0,0){$0$}}
%\put(9,-9){\makebox(0,0){$\ddots$}}
\put(8.8,-8.8){\makebox(0,0){$\cdot$}}
\put(9.1,-9.1){\makebox(0,0){$\cdot$}}
\put(9.4,-9.4){\makebox(0,0){$\cdot$}}
\put(10,-10){\makebox(0,0){$0$}}
\end{picture}
\right)
\]


\end{document}
3
  • +1 for using a picture environment.
    – Mico
    Dec 9, 2013 at 22:34
  • 2
    The second solution is pretty good. It seems a lot of code but nothing that can not be solved with a macro.
    – osjerick
    Dec 9, 2013 at 22:56
  • @OSjerick Yep, and I would have upvoted David's answer at the drop of a hat … if only it did use a macro for this ;)
    – Christian
    Jan 4, 2014 at 22:28
4

Here I did 2 things to the OP's MWE. I used a TABstack with \fixTABwidth{T} to auto set all column widths the same; and I designed an \xddots to be more diagonal.

\documentclass{article}
\usepackage{tabstackengine,amsmath}
\TABstackMath
\fixTABwidth{T}
\newcommand\xddots{\stackunder[2.5pt]{\stackanchor[2.8pt]{\kern-14pt.}{.}}{\kern14pt.}}
\begin{document}
\[
\mathrm{Mat}(u;\mathcal{B})=
\parenMatrixstack{
I_{n_+}     &&&&&&&&&\\
&-I_{n_-}    &&&&&&&&\\
&&R_{\theta_1}&&&&&&&\\
&&&R_{\theta_2}&&&&&&\\
&&&&\xddots      &&&&&\\
&&&&&R_{\theta_r}&&&&\\
&&&&&&0           &&&\\
&&&&&&&0           &&\\
&&&&&&&&\xddots      &\\
&&&&&&&&&0
}
\]
\end{document}

enter image description here

4

Instead of writing anything, simply leave the cell blank and array will take care of it. Here is the code

\begin{equation}
\rho _{\epsilon} = \left( \begin{array}{ccccc}
\epsilon &  &  &  &  \\
 & \epsilon &  &  &  \\
 &  & \ddots & &  \\
 &  &  & \epsilon &  \\
 &  &  &  & \epsilon \\
\end{array} \right)
\end{equation}

The result looks like

diagonal matrix

Using environment pmatrix would be a great idea, but it is hard to take care of the spacing and alignment.

0
1

With {pNiceMatrix} of nicematrix. The key columns-width=auto assures that all the columns will have the same width and then that the centers of cells on the diagonal are aligned (since you know that all the rows have the same height and depth). Then, I use the built-in command \line (available in the so-called \CodeAfter) which draws that dotted lines with Tikz (in fact, the sublayer of Tikz).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
\[
    \mathrm{Mat}(u;\mathcal{B})=
    \begin{pNiceMatrix}[columns-width=auto,xdots/shorten = 2mm]
        I_{n_+}\\
        &-I_{n_-}\\
        &&R_{\theta_1}\\
        &&&R_{\theta_2}\\
        &&&&\\
        &&&&&R_{\theta_r}\\
        &&&&&&0\\
        &&&&&&&0\\
        &&&&&&&&\\
        &&&&&&&&&0\\
    \CodeAfter \line{4-4}{6-6} \line{8-8}{10-10}
    \end{pNiceMatrix}
\]
\end{document}

Output of the above code

You must log in to answer this question.

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