10

I am trying to typeset a list of vectors spanning a multidimensional space, using the notation span{v_1,v_2,...,v_n} (I haven't found out how to inline it as rendered latex)

i.e.:

span \{
  \begin{pmatrix} 1      \\ \vdots \\ \vdots \\ 1      \\ 1      \end{pmatrix},
  \begin{pmatrix} 0      \\ 1      \\ \vdots \\ \vdots \\ 1      \end{pmatrix},
  \begin{pmatrix} 0      \\ 0      \\      1 \\ \vdots \\ 1      \end{pmatrix}
  \begin{matrix}  \cdots \\        \\ \ddots \\ \ddots \\ \cdots \end{matrix}
  \begin{pmatrix} 0      \\ \vdots \\ \vdots \\      0 \\ 1      \end{pmatrix}
\}

but the fourth "vector", consisting of only various dots does not have the same size as the other vectors, since the dots take up more vertical space than 1 or 0 do.

I understand LaTeX doesn't know how to align them since they are all independent matrices but I'm not satisfied with the result. Is there any way to make them all have the same height?

1
  • 1
    TeX.SE has rendered latex disabled. you can read about it in the meta. it caused too many problems because it was triggered when not wanted. Commented Oct 31, 2010 at 14:20

5 Answers 5

8

You may want to take a look at easybmat:

\documentclass{article}
\usepackage{easybmat}

%\usepackage{etex} % if you also want tikz, then you also need etex,
%\usepackage{tikz} % and they have to be loaded AFTER easybmat

\newenvironment{bvec}[1]{\begin{BMAT}(r)[0pt]{c}{#1}}{\end{BMAT}}
\newenvironment{pbvec}[1]{\left(\begin{bvec}{#1}}{\end{bvec}\right)}

\begin{document}
$span \{
\begin{pbvec}{ccccc} 1      \\ \vdots \\ \vdots \\ 1      \\ 1      \end{pbvec},
  \begin{pbvec}{ccccc} 0      \\ 1      \\ \vdots \\ \vdots \\ 1      \end{pbvec},
  \begin{pbvec}{ccccc} 0      \\ 0      \\      1 \\ \vdots \\ 1      \end{pbvec}
  \begin{bvec}{ccccc}  \cdots \\  {}      \\ \ddots \\ \ddots \\ \cdots \end{bvec}
  \begin{pbvec}{ccccc} 0      \\ \vdots \\ \vdots \\      0 \\ 1      \end{pbvec}
\}$
\end{document}

which results in

alt text

There are a few annoying things with BMAT:

  • You must declare the number of columns at the top (I have no idea why, but I guess this has to do with the fact that they can be align differently or something)
  • You cannot have empty rows (see {} in the fourth line).
11
  • 3
    I'm assuming this was typed up without too much work, but for the sake of the OP, might use \left\{ and \right\} to have the braces encompass the vectors, and use \text{span} to have it typeset properly. At least that's the way my linear algebra professor does it.
    – EricR
    Commented Oct 31, 2010 at 14:19
  • 2
    Instead of \text, you should \mathrm (so that it does not inherit formatting from the surrounding text).
    – Caramdir
    Commented Oct 31, 2010 at 17:02
  • 1
    Hmmm. I don't like telling people what they should do. The OP asked about how to make the vectors the same size and that is what I wanted to focus my answer on. I actually think it looks better with the small braces, in this case, and about the word "span", well, the OP can decide what he wants to do. I'd rather no evangelize. Feel free to comment on the original question, or add an alternative answer if you like. Commented Oct 31, 2010 at 20:50
  • 1
    How about \operatorname{span} or, since this is likely a common thing to want, \DeclareMathOperator{\span}{span} in the preamble and then use \span.
    – TH.
    Commented Oct 31, 2010 at 21:17
  • It works like a charm, thanks a lot! As for the \{, I also think it looks better when it's small but that clearly is a matter of taste.
    – jonny
    Commented Nov 1, 2010 at 8:36
5

I'd like to expand a bit on Yossi's answer. If you look at the image he provided, then you can see that the \vdots and the \ddots are rather low; they don't look vertically centered. The reason seems to be that the definition of \vdots in plain.tex and the BMAT don't work together well: The {ccccc} part in Yossi's answer means that all the 5 entries in the vector are vertically centered, and the plain TeX definition of \vdots is

\def\vdots{\vbox{\baselineskip4\p@ \lineskiplimit\z@
    \kern6\p@\hbox{.}\hbox{.}\hbox{.}}}

Thus, \vdots is a vertical box containing 6pt white space and 3 evenly spaces dots, and one shouldn't be too surprised that the dots are sitting too low in the BMAT vector. I still don't quite understand why \vdots is defined like this, but is does work together well with plain TeX's \pmatrix. In the following image you can compare \pmatrix{1\cr \vdots\cr \vdots\cr 1\cr 1} from plain TeX, \begin{pmatrix} 1 \\ \vdots \\ \vdots \\ 1 \\ 1 \end{pmatrix} from amsmath, and the vector produced by Yossi's pbvec:

Unfortunately I can't explain all the differences. For me the plain TeX vector looks best, even if I'd like to have the parentheses a bit closer to the numbers, as in the other vectors. To get a similar result with BMAT, it does not help using "t" or "b" instead of "c", which would give "top" or "bottom" vertical alignment. The only idea I have is to define vertically centered \vdots, so here's the solution I would suggest:

\documentclass{article}
\usepackage{amsmath,easybmat}

\newcommand*{\bvector}[1]{\begin{BMAT}(r)[0pt]{c}{ccccc}#1\end{BMAT}}
\newcommand*{\pbvector}[1]{\left(\bvector{#1}\right)}
\makeatletter
\def\vcdots{\vbox{\baselineskip4\p@ \lineskiplimit\z@
    \kern3\p@\hbox{.}\hbox{.}\hbox{.}\kern3\p@}}
\makeatother

\begin{document}
$\operatorname{span} \{
  \pbvector{ 1      \\ \vcdots \\ \vcdots \\ 1       \\ 1      },
  \pbvector{ 0      \\ 1       \\ \vcdots \\ \vcdots \\ 1      },
  \pbvector{ 0      \\ 0       \\ 1       \\ \vcdots \\ 1      }
  \bvector{  \cdots \\ {}      \\ \ddots  \\ \ddots  \\ \cdots }
  \pbvector{ 0      \\ \vcdots \\ \vcdots \\ 0       \\ 1      }
\}$

\end{document}

Note that I haven't changed the \ddots, so they are a bit lower than the \vdots, but of course this could be fixed, too.

One last word that explains why BMAT yields the desired alignment: I think it sets the height of all the entries in the vector to the maximum height it finds in the vector. So here it works since for all the vectors this maximum height is the same. It goes terribly wrong if in the third vector you replace \vcdots with, say, 0.

2

I've been playing around with this in plain-tex and wondered how do you feel about this:

span $
  \def\svdots{\lower1pt\hbox{$\smash\vdots$}}
  \def\sddots{\lower1pt\hbox{$\smash\ddots$}}
\{
  \pmatrix{1\cr       \svdots\cr  \svdots\cr  1\cr        1},
  \pmatrix{0\cr       1\cr        \svdots\cr  \svdots\cr  1},
  \pmatrix{0\cr       0\cr        1\cr        \svdots\cr  1}
  \matrix {\cdots\cr  \cr         \sddots\cr  \sddots\cr  \cdots\cr}
  \pmatrix{0\cr       \svdots\cr  \svdots\cr  0\cr        1}
\}$
\bye

1

The mechanism in stackengine's ...Vectorstack series of macros uses a technique that preserves the baselineskip between rows, so that the vertical alignment between unique vector stacks is preserved. The baselineskip for these so-called "long" stacks is set by \setstackgap{L}{<length>}.

\documentclass{article}
\usepackage{amsmath,stackengine}
\setstackEOL{\\}
\setstackgap{L}{16pt}
\begin{document}
$\mathrm{span} \{
  \parenVectorstack{ 1      \\ \vdots \\ \vdots \\ 1      \\ 1      },
  \parenVectorstack{ 0      \\ 1      \\ \vdots \\ \vdots \\ 1      },
  \parenVectorstack{ 0      \\ 0      \\      1 \\ \vdots \\ 1      }
  \Vectorstack{  \cdots \\        \\ \ddots \\ \ddots \\ \cdots }
  \parenVectorstack{ 0      \\ \vdots \\ \vdots \\      0 \\ 1      }
\}$
\end{document}

enter image description here

1

You can do that with {NiceMatrix} of nicematrix (with a perfect result for the dotted lines). You need at least v. 5.15 (2021-04-25).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$
\text{span}
\{
\begin{NiceArray}{(c)c(c)c(c)c(c)}[xdots/shorten=5pt,baseline=3,nullify-dots]
1      &   & 0      &   & 0      & \cdots & 0      \\
\Vdots &   & 1      &   & 0      &        & \Vdots \\
       & , & \Vdots & , & 1      &        &        \\
1      &   &        &   & \Vdots &        & 0 \\
1      &   & 1      &   & 1      & \cdots & 1 \\
\CodeAfter [xdots/shorten=15pt]
  \line{2-5}{4-7}
  \line{3-5}{5-7}
\end{NiceArray}
\}
$

\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 .