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.
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.
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}}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.
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.
Pitfalls
\vec{AB}puts the short arrow over the middle of both letters. Use\overrightarrow{AB}, or\vv{AB}from theesvectpackage for a stretching arrow with a small tip.\vecin normal text stops with Missing $ inserted.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
amsmath - Package
bm - How-to Bold math symbols in LaTeX
- How-to Matrices in LaTeX
- How-to Absolute value and norm in LaTeX