Vector in LaTeX
Updated:
A vector with an arrow is written as \vec{v}. University textbooks more often use bold, \mathbf{v}. Pick one convention and stick with it throughout the document.
Try it with your own values
Edit the code and the preview updates as you type.
\vec{F} = m\vec{a} \qquad \mathbf{F} = m\mathbf{a}Copying this from handwritten notes? Snap a photo of the page and CamteX turns the formulas into LaTeX. Try it free
\hat{\imath}, \hat{\jmath}, \hat{k}\vec{a} \cdot \vec{b} = |\vec{a}||\vec{b}|\cos\alpha, \quad \vec{a} \times \vec{b}\overrightarrow{AB}\vec{v} = (3, 4, 12), \quad |\vec{v}| = \sqrt{3^2 + 4^2 + 12^2} = \sqrt{169} = 13, \quad \lVert \mathbf{v} \rVertSingle bars give the length of a vector in physics, double bars the norm in linear algebra. \lVert and \rVert from amsmath mark the opening and closing side, so the spacing stays right after a minus sign or a function name. The components form a Pythagorean quadruple, which makes a handy check.
\mathbf{v} = \begin{pmatrix} 3 \\ -1 \\ 2 \end{pmatrix}, \quad \mathbf{v}^{\mathsf{T}} = (3, -1, 2), \quad \mathbf{v}^{\mathsf{T}} \mathbf{v} = 14pmatrix from amsmath stacks the components in round brackets. In running text a row vector with a transpose saves three lines of height. Set the T upright with \mathsf or \mathrm, since an italic T looks like a power of a variable called T. The product of the transpose with the vector is the squared length, 9 + 1 + 4.
\mathbf{r} = x\,\mathbf{e}_x + y\,\mathbf{e}_y + z\,\mathbf{e}_z, \quad \mathbf{e}_x \cdot \mathbf{e}_y = 0Engineering and continental European texts write unit vectors as e with a subscript instead of i, j and k with hats. The thin space \, separates a coordinate from its basis vector, so x e_x does not read as a product of three letters. The dot product of two different basis vectors is zero.
\mathbf{F} = m\mathbf{a} \qquad \bm{F} = m\bm{a} \qquad U = -\bm{\mu} \cdot \mathbf{B}\mathbf sets letters bold and upright and leaves lowercase Greek untouched. \bm from the bm package keeps the italic shape and works on any symbol, which gives the bold italic vectors that ISO 80000-2 and many physics journals ask for. Here it bolds mu, the magnetic moment, in the energy of a dipole.
\vec{a} \times \vec{b} = \begin{vmatrix} \hat{\imath} & \hat{\jmath} & \hat{k} \\ 1 & 2 & 3 \\ 4 & 5 & 6 \end{vmatrix} = (-3, 6, -3)vmatrix draws the bars of a determinant. Expanding along the first row turns each component into a 2 by 2 determinant: 2 times 6 minus 3 times 5 gives -3 for the first. Check the result with a dot product: with a it is -3 + 12 - 9 = 0, so the result is perpendicular to a.
\cos\theta = \frac{\vec{a} \cdot \vec{b}}{|\vec{a}|\,|\vec{b}|} = \frac{0 + 0 + 1}{\sqrt{2}\,\sqrt{2}} = \frac{1}{2} \implies \theta = 60^\circWith a = (1, 0, 1) and b = (0, 1, 1) only the third components multiply to something other than zero. The thin space between the two magnitudes keeps their bars from merging into the double bar of a norm. \cdot is the centred dot of the scalar product, never a full stop.
\nabla f, \quad \nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0}, \quad \nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t}\nabla in front of a scalar is the gradient, with \cdot it is the divergence and with \times the curl. The two equations are Gauss's law and Faraday's law from Maxwell's equations. Some books set the operator in bold with \boldsymbol{\nabla} or spell it out as \operatorname{div} and \operatorname{curl}.
Common mistakes and fixes
| Wrong | Right | Why |
|---|---|---|
||\mathbf{v}|| | \lVert \mathbf{v} \rVert | Two keyboard bars are two separate symbols with a gap between them, and they have no opening or closing side. |
\mathbf{\omega} | \boldsymbol{\omega} | \mathbf has no bold lowercase Greek, so the angular velocity stays in normal weight. |
\hat{i}, \hat{j} | \hat{\imath}, \hat{\jmath} | The hat and the dot of the letter collide; \imath and \jmath are i and j without the dot. |
\vec{a} . \vec{b} | \vec{a} \cdot \vec{b} | A full stop sits on the baseline, while the dot product sign is centred on the line. |
\mathbf{v}^T | \mathbf{v}^{\mathsf{T}} | An italic T reads as an exponent named T rather than as the transpose. |
- \vec{AB} for a segment: the arrow covers only one letter. Over two letters use \overrightarrow.
- Using * or x as the cross product instead of \times.
See also
- Matrix in LaTeX
- Derivative in LaTeX
- Greek letters in LaTeX
- Equation numbering in LaTeX
- Aligned equations in LaTeX
- Math symbols in LaTeX
Don't want to memorize commands?
Draw a formula or paste a screenshot, and CamteX turns it into ready LaTeX.