How to write a vector in LaTeX?

# How to write a vector in LaTeX?

This post may contain affiliate links that allow us to earn a commission at no expense to you. Learn more

This article aims to show you a simple way to create a vector in LaTeX.

Regardless of where you look in science books, you will find at least a vector somewhere in one of its many representations, and that’s because it is used for many things in science subjects. And if you are using LaTeX you will want to know how to insert vectors in your document.

## Vectors

According to its definition a vector is a geometric object that has magnitude and direction, and has properties according to vector algebra. Usually represented graphically as an arrow connecting two points A, B and denoted by

$$\overrightarrow{AB} \qquad \vec{r}$$


## Vec command

The standard command to call the arrow above the letter is \vec{} it takes one value as an argument, but it has a disadvantage, it does not cover the entire argument. Instead you can use \overrightarrow{} likewise it takes one value as argument, for example

$$\vec{r} \qquad %standard \vec{AB} \qquad %the arrow does not cover all the letters \overrightarrow{AB}$$ %the arrow covers all the letters


## Vectors in Math mode

You probably already noticed it, to call the vector commands you have to use math mode, more examples

\documentclass{article}
\usepackage{amssymb}
\begin{document}
$$\vec{r}=x\hat{i}+y\hat{i}+z\hat{k}$$
$$\vec{\mathbf{F}}=m\vec{\mathbf{a}}$$

\begin{center}
If $\vec{\mathbf{a}}_{net}$ is 0, then
$\vec{\mathbf{F}}_{net} = \vec{0}$
\end{center}

\end{document}


## Vector with physics package

Now the physics package allows you to write the same vector arrow above the letters but with more options, for example without having to use a command for the boldness. The command for the vector is \va{} and \va*{} and for the bold font \vb{} and \vb*{}. For example

\usepackage{physics}
...
$$\vec{\mathbf{F}}=\vec{0}$$ % two commands
$$\vb{F}\,,\,\vb*{F}$$ %one command
$$\vec{r}=x\hat{i}+y\hat{i}+z\hat{k}$$ %no package
$$\va{r}\,,\,\va*{r}$$ %with package

\end{document}


Two things to notice, first the commands with the * generated a cursive font, and second the \vb{} and \vb*{} command does not generate an arrow above the argument, this form is another way to represent vectors in textbooks and documents, especially in physics.

Now you have the knowledge on how to write vectors in LaTeX in multiple ways, I prefer the physics package to write it due to its smoothness and simplicity, but that is up to you to decide.

I hope this post was helpful in you path using LaTeX, and as always keep writing in LaTeX.