# Diagonal dots spanning multiple lines/columns of a matrix

I'm filling in large sparse matrices, for example

\begin{bmatrix}
0  & -2     & 1      &        & -1     & 2  \\
2  & \ddots & \ddots & \ddots &        & -1 \\
-1 & \ddots & \ddots & \ddots & \ddots &    \\
& \ddots & \ddots & \ddots & \ddots & 1  \\
1  &        & \ddots & \ddots & \ddots & -2 \\
-2 & 1      &        & -1     & 2      & 0
\end{bmatrix}


I do not like the way the dots are spaced. I would like them to be equally spaced across the diagonals. I guess this can be done using TikZ but is there an easier way?

-
Welcome to TeX.sx! As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. – Torbjørn T. Dec 19 '11 at 22:15
Are the entries that are not specified supposed to be zero? – Peter Grill Dec 19 '11 at 22:45
@PeterGrill: Yes. – ZulfiqarIII Dec 19 '11 at 23:01

It's not difficult with TikZ. I have just removed the ddots

\documentclass{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{matrix}
\begin{document}
Following quadratic form involves a skew symmetric matrix.
$$\begin{pmatrix} a\\b\\\vdots\\z \end{pmatrix}^T \begin{tikzpicture}[baseline=(current bounding box.center)] \matrix (m) [matrix of math nodes,nodes in empty cells,right delimiter={]},left delimiter={[} ]{ 0 & -2 & 1 & & -1 & 2 \\ 2 & & & & & -1 \\ -1 & & & & & \\ & & & & & 1 \\ 1 & & & & & -2 \\ -2 &1 & & -1 & 2 & 0\\ } ; \draw[loosely dotted] (m-1-1)-- (m-6-6); \draw[loosely dotted] (m-1-2)-- (m-5-6); \draw[loosely dotted] (m-2-1)-- (m-6-5); \end{tikzpicture}\begin{pmatrix} a\\b\\\vdots\\z \end{pmatrix}=0 \label{eq:eqq1}$$

\end{document}


It looks slightly faint in the picture but if you wish you can add the option thick to the draw commands.

-
I've chosen this method because it requires the least modification. – ZulfiqarIII Dec 20 '11 at 13:36

Such diagonals are definitely possible using graphic packages like tikz/pgf or pstricks. However, here's one using TeX leaders:

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\newcommand{\diagdots}[3][-25]{%
\rotatebox{#1}{\makebox[0pt]{\makebox[#2]{\xleaders\hbox{$\cdot$\hskip#3}\hfill\kern0pt}}}%
}
\begin{document}
$\begin{bmatrix} 0 & -2 & 1 & & -1 & 2 \\ 2 & & & & & -1 \\ -1 & & & & & \\ & & \multicolumn{2}{c}{\smash{\raisebox{.5\normalbaselineskip}{\diagdots{8em}{.5em}}}} & & 1 \\ 1 & & & & & -2 \\ -2 & 1 & \phantom{-2} & -1 & 2 & 0 \end{bmatrix}$
\end{document}


The minimal example provides \diagdots[<angle>]{<len>}{<skip>} that draws a diagonal array of dots (actually \cdots) of length <len> at an angle of <angle> (default is -25). The <skip> defines the approximate length between dots.

I've placed \diagdots in the middle of your bmatrix (horizontally by using \multicolumn{2}{c}{...} and vertically by using \raisebox{.5\normalbaselineskip}{...}), and \smashed it to remove any vertical height distortion. The \diagdots output has zero width (by virtue of \makebox[0pt]).

You can play around with the lengths and angles so see what suits you.

-

Ellipses are usually used to indicate that something is repeated. In this case you want to indicate that the 0 entry is repeated, and hence should show that there is a 0 on either end of the ellipses.

So, assuming that there are a fixed number of rows (as your example seems to indicate), then I would just use \cdots in either one column or both:

If the number of rows is not fixed, then I would use one of the following. My preference would be the last one as then there is no confusion as to where the 0s are.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
$\begin{bmatrix} 0 & -2 & 1 & 0 & -1 & 2 \\ 2 & 0 & & \cdots & 0 & -1 \\ -1 & 0 & & \cdots & 0 & 0 \\ 0 & 0 & & \cdots & 0 & 1 \\ 1 & 0 & & \cdots & 0 & -2 \\ -2 & 1 & 0 & -1 & 2 & 0 \end{bmatrix} % \begin{bmatrix} 0 & -2 & 1 & 0 & -1 & 2 \\ 2 & 0 & \cdots & \cdots & 0 & -1 \\ -1 & 0 & \cdots & \cdots & 0 & 0 \\ 0 & 0 & \cdots & \cdots & 0 & 1 \\ 1 & 0 & \cdots & \cdots & 0 & -2 \\ -2 & 1 & 0 & -1 & 2 & 0 \end{bmatrix}$

If the number of rows is not fixed:
$\begin{bmatrix} 0 & -2 & 1 & 0 & -1 & 2 \\ 2 & 0 & & \cdots & 0 & -1 \\ -1 & 0 & & \cdots & 0 & 0 \\ 0 & 0 & & \cdots & 0 & 0 \\ \vdots & \vdots & & \vdots & \vdots & \vdots \\ 0 & 0 & & \cdots & 0 & 0 \\ 0 & 0 & & \cdots & 0 & 1 \\ 1 & 0 & & \cdots & 0 & -2 \\ -2 & 1 & 0 & -1 & 2 & 0 \end{bmatrix} % \begin{bmatrix} 0 & -2 & 1 & 0 & -1 & 2 \\ 2 & 0 & \cdots & \cdots & 0 & -1 \\ -1 & 0 & \cdots & \cdots & 0 & 0 \\ 0 & 0 & \cdots & \cdots & 0 & 0 \\ \vdots & \vdots & \ddots & & \vdots & \vdots \\ \vdots & \vdots & & \ddots & \vdots & \vdots \\ 0 & 0 & \cdots & \cdots & 0 & 0 \\ 0 & 0 & \cdots & \cdots & 0 & 1 \\ 1 & 0 & \cdots & \cdots & 0 & -2 \\ -2 & 1 & 0 & -1 & 2 & 0 \end{bmatrix}$

\end{document}

-
I think we misunderstood each other. The blank entries are assumed to be zero, but the nonzero entries are repeated diagonally. – ZulfiqarIII Dec 20 '11 at 13:38

runt it with xelatex

\documentclass{article}
\usepackage{mathtools}
\usepackage{pst-node}
\begin{document}
Following quadratic form involves a skew symmetric matrix.
$$\label{eq:eqq1} \begin{pmatrix*}[r] a\\b\\c\\\vdots\\z \end{pmatrix*}^T \begin{bmatrix*}[r] \rnode[rb]{C}{0} & \rnode[rb]{B}{-2} & \rnode[rb]{A}{1} & & -1 & 2 \\ \rnode[rb]{D}{2} & & & & & -1 \\ \rnode[rb]{E}{-1} & & & & & \\ & & & & & \rnode[l]{a}{1} \\ 1 & & & & & -\rnode[l]{b}{2} \\ -2 &1& & -\rnode[l]{e}{1} & \rnode[rb]{d}{2} & \rnode[l]{c}{0}\\ \end{bmatrix*} \begin{pmatrix*}[r] a\\b\\c\\\vdots\\z \end{pmatrix*}=0 \psset{linestyle=dotted,nodesep=2mm} \ncline{A}{a}\ncline{B}{b}\ncline{C}{c}\ncline{D}{d}\ncline{E}{e}$$

\end{document}


-