# Centering \vdots in a sparse matrix with an even number of rows

I am trying to define only the non-zeros elements in a sparse matrix, thus using some \vdots where the entries are zeros and specifying the row when needed (using the blockarray command, with \usepackage{blkarray} in the preamble). My matrix only has 2 columns (or 4), so I can't center the \vdots like I would like (the problem would be solved if the matrix had an odd number of columns). Here's an exemple:

$\begin{blockarray}{ccc} \begin{block}{[cc]l} \vdots \\ a & b & /K-1 \\ c & d & /K \\ \vdots \\ \end{block} \end{blockarray}$


As you can see in this example, while I specified to center the entries inbetween [ and ], the \vdots are centered on the first column. If I replace cc by any combination of r, c, and l it is still not satisfying. Also if I put the \vdots between any number of & on the right and/or on the left it still doesn't work.

The other solution I have (but not satisfactory either) is to add another column:

$\begin{blockarray}{cccc} \begin{block}{[ccc]l} &\vdots& \\ a & & b & /K-1 \\ c & & d & /K \\ &\vdots& \\ \end{block} \end{blockarray}$


But as you can see now the non-zeros entries are too far apart and the result is not really pretty.

-
Hello, and welcome! Please post a Minimal Working Example, it will help other work on your problem! – Timothée Poisot Dec 14 '12 at 2:43
Take a look at Mathmode.sty (a pure documentation file on CTAN, it shows how to solve many mathematical typesetting problems). – vonbrand Jan 2 '13 at 10:20

blkarray is able to do it without extra packages, just use \BAmulticolumn, which is the specific command for a blockarray:

\documentclass{article}
\usepackage{blkarray}

\begin{document}

$\begin{blockarray}{ccc} \begin{block}{[cc]l} \BAmulticolumn{2}{c}{\vdots} & \\ a & b & /K-1 \\ c & d & /K \\ \BAmulticolumn{2}{c}{\vdots} & \\ \end{block} \end{blockarray}$

\end{document}


-
That's even better. Thank you egreg – KKP Dec 14 '12 at 21:21

Two possibilities: the first one uses an additional column and the @{...} construct to decrease the inter-column spacing; the second one uses \tikzmark to place some marks and then places the \vdots using the marks.

\documentclass{article}
\usepackage{blkarray}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand\tikzmark[1]{%
\tikz[remember picture,overlay] \node (#1) {};}

\begin{document}

$\begin{blockarray}{cccc} \begin{block}{[c@{\hspace{3pt}}c@{\hspace{3pt}}c]l} &\vdots& \\ a & & b & /K-1 \\ c & & d & /K \\ &\vdots& \\ \end{block} \end{blockarray}$

$\begin{blockarray}{ccc} \begin{block}{[cc]l} \tikzmark{a} & \tikzmark{b} \\ a & b & /K-1 \\ c & d & /K \\ \tikzmark{c} & \tikzmark{d} \\ \end{block} \end{blockarray}$
\begin{tikzpicture}[remember picture,overlay]
\node[yshift=0.5ex] at ( $(a)!0.5!(b)$ ) {$\vdots$};
\node[yshift=1.7ex] at ( $(c)!0.5!(d)$ ) {$\vdots$};
\end{tikzpicture}

\end{document}


-
Thank you very much. My terms are not exactly a b c d, but larger expressions. What is the default size of the additional column in pt? – KKP Dec 14 '12 at 2:17
@KKP The width of the contents plus 5.0pt (the default value for \arraycolsep) on both sides. – Gonzalo Medina Dec 14 '12 at 2:20