Vectors in LaTeX (vec, overrightarrow, bold)

\vec{v} puts an arrow over a single letter. \overrightarrow{AB} draws an arrow over several letters, and \mathbf{v} or \bm{v} writes the vector in bold instead.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{amsmath}
\usepackage{bm}

Vector with an arrow

The arrow of \vec has a fixed width that fits one letter. \overrightarrow stretches over its whole argument.

\[
  \vec{F} = m \vec{a}
  \qquad
  \vec{a} + \vec{b}
  \qquad
  \overrightarrow{AB}
\]
Change the formula

The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.

F⃗=ma⃗a⃗+b⃗AB→\vec{F} = m \vec{a} \qquad \vec{a} + \vec{b} \qquad \overrightarrow{AB}

Open this formula in the editor

Vector in bold

\mathbf{v} prints an upright bold letter. \bm{v} from the bm package prints a bold italic letter and also works for Greek letters.

\[
  \mathbf{v} = \mathbf{a} + \mathbf{b}
  \qquad
  \bm{v} = \bm{\omega} \times \bm{r}
\]
Change the formula

The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.

v=a+bv=ω×r\mathbf{v} = \mathbf{a} + \mathbf{b} \qquad \bm{v} = \bm{\omega} \times \bm{r}

Open this formula in the editor

Switch the notation for the whole document

Write \vec{v} everywhere and decide in the preamble what it prints. This line turns every \vec into a bold letter.

This goes into the preamble.

\renewcommand{\vec}[1]{\mathbf{#1}}

Open in the editor

Unit vectors and products

\hat{e} puts a hat on a letter. \cdot is the dot of a scalar product and \times the cross of a vector product. \imath and \jmath are i and j without a dot, so an arrow or hat does not collide with it.

\[
  \hat{e}_x
  \qquad
  \vec{a} \cdot \vec{b}
  \qquad
  \vec{a} \times \vec{b}
  \qquad
  \vec{\imath} + \vec{\jmath}
\]
Change the formula

The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.

e^xa⃗⋅b⃗a⃗×b⃗ı⃗+ȷ⃗\hat{e}_x \qquad \vec{a} \cdot \vec{b} \qquad \vec{a} \times \vec{b} \qquad \vec{\imath} + \vec{\jmath}

Open this formula in the editor

Column and row vectors

A column vector is a matrix with one column: pmatrix from amsmath with \\ between the entries. A row vector is written with commas in parentheses.

\[
  \vec{v} = \begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix}
  \qquad
  \vec{w} = (w_1, w_2, w_3)^{\mathsf{T}}
\]
Change the formula

The preview is drawn in your browser by KaTeX, which knows the common math commands. The editor compiles the formula with pdfTeX.

v⃗=(123)w⃗=(w1,w2,w3)T\vec{v} = \begin{pmatrix} 1 \\ 2 \\ 3 \end{pmatrix} \qquad \vec{w} = (w_1, w_2, w_3)^{\mathsf{T}}

Open this formula in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages