Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

Thank you for your time and your help.

share|improve this question
1  
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
add comment

2 Answers

up vote 3 down vote accepted

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}

enter image description here

share|improve this answer
    
That's even better. Thank you egreg –  KKP Dec 14 '12 at 21:21
add comment

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}

enter image description here

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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