45

enter image description hereenter image description here

I'm trying to input an arrow vector (a column vector, see the picture) in an align environment, but it reports an error.

Can someone show me the TeX code of it in an align environment?

ChrisS
  • 13,529
dream_big
  • 451

3 Answers3

65

You can use bmatrix from amsmath with \vdots:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
  \begin{align}
    y &= \begin{bmatrix}
           x_{1} \\
           x_{2} \\
           \vdots \\
           x_{m}
         \end{bmatrix}
  \end{align}
\end{document}

the matrix y

Answering to the comment:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
  \begin{align}
    y &= (x_{1},x_{2},\cdots, x_{N})
        \begin{pmatrix}
          \begin{bmatrix}
           ax_{0} + bx_{1} \\           
           \vdots \\
           ax_{n-1}+bx_{n}
          \end{bmatrix} -
          \begin{bmatrix}
           z_{1} \\
           \vdots \\
           z_{n}
         \end{bmatrix}
    \end{pmatrix}
  \end{align}
\end{document}

enter image description here

user43963
  • 1,570
12

A recommended solution. Adapt it to suit your need.

\documentclass[preview,border=12pt,12pt,varwidth]{standalone}% change this setting back to \documenctclass{article}!
\usepackage{amsmath}

\def\A{
\begin{bmatrix}
    x_1 & x_2 & \cdots & x_N
\end{bmatrix}}

\def\B{
\begin{bmatrix}
    ax_0 + bx_1 \\
    ax_1 + bx_2 \\
    \vdots \\
    x_{N-1} + x_N
\end{bmatrix}}

\def\C{
\begin{bmatrix}
    z_1 \\
    z_2 \\
    \vdots \\
    z_N
\end{bmatrix}}

\begin{document}
\abovedisplayskip=0pt\relax% don't use this line in your production!
\begin{equation}
y =\A \left(\B - \C\right)
\end{equation}
\end{document}

enter image description here

Suggestions:

  • Avoid using {} for a one-digit number (0, 1, 2, ..., 9), a Latin letter (a, b, c, ..., z), a Greek letter such as (\alpha, \beta, \gamma, ...) as a subscript (or superscript). For example, x_{2} should be written as x_2, x_{N} should be written as x_N and x_{\alpha} should be written as x_\alpha. It makes the code not only easy to read but also save more keystrokes. Note from @egreg: x_{\notin} cannot be written as x_\notin. Note from me: x_{\sin} cannot be written as x_\sin.

  • For the sake of consistency, use the same bracket for column and row vectors. For example, (x_1,x_2,\cdots,x_N) should be written as \begin{bmatrix} x_1 & x_2 & \cdots & x_N\end{bmatrix}.

  • If you have just one line of equation with an equation number, use equation instead of align.

  • Use def or newcommand (recommended) to decompose complicated equations into several reusable parts such that the complicated equations become easy to read and the smaller parts can be reused consistently everywhere in your documents.

0

for such input you can use package {simples-matrices}

\usepackage{simples-matrices}
\matrice(b)[1]{$z_1, z_2,\dots, z_n$}
y=\matrice(b)[4]{$x_1,x_2,\dots,x_n$}

the (b) provides bracket on matrices, [n] gives n cols of matrix. (check package documentation on ctan). which sometimes you will need to format and adjust spacing, while personally I do feel this package makes things easier.