How to write and format vectors in LaTeX?

In this tutorial, our main goal is to study mathematical quantities that have a direction. By learning to write vectors properly in LaTeX, you will be better prepared to solve many problems in math and physics.

Different Formats for Representing Vectors

LaTeX offers simple commands for writing mathematical expressions, giving you control over how they appear.

Arrow over a letter

The most common way to show a vector is by placing an arrow above a letter. In LaTeX, you do this with the \vec command.

\[ \vec{p} \]

Output :

arrow over p

When you compile this, you will see a neat arrow over p.

\[ \vec{p}=m\vec{v} \]

Output :

arrow over v

However, when you try to put an arrow over more than one letter, like AB, the arrow will not cover the entire group.

\documentclass{article}
\begin{document}
   \[ \vec{AB} \]
\end{document}

Output :

Incorrect arrow over AB

To fix this, use the \overrightarrow command, which adjusts the arrow length.

\[ \overrightarrow{AB} \]

Output :

Correct arrow using \overrightarrow

Even though the arrow now covers the letters properly, the visual appearance might not always be ideal.

esvect package

A better option is to use the esvect package. This package offers a more attractive arrow that adjusts well to different characters.

\documentclass{article}
\usepackage[a]{esvect}
\begin{document}
  \[ \vv{r} \]
  \[ \vv{\ddot{r}} \]
  \[ \vv{r_{n}} \]
  \[ \vv{xyz} \]
  \[ \vv{pqr} \]
\end{document}
Using esvect package

Using esvect package

Bold Format

To make a vector stand out, you can also use bold formatting. This is done with the \mathbf command.

\[ \textbf{AB} \]

Output :

If you need to bold special symbols, such as Greek letters, use the \bm or \boldsymbol command. This way, even symbols like θ and φ will appear in bold.

Hat Notation for Unit Vectors

For unit vectors, a hat is placed above the variable using the \hat command. For example:

\[ \hat{a}=\frac{\vec{a}}{\left | \vec{a} \right |} \]

Output :

Using hat symbol

This command places a small hat over a.

Magnitude of a vector

The magnitude of a vector is written using absolute value bars. In LaTeX, you use \left| and \right| to let the bars adjust to the size of the expression.

\[ \left| \vec{a} \right| \]

Output :

Using absolute value bars to represent the magnitude of a vector.

This method is simple and does not require any extra packages.

Position Vector

A position is represented by three rectangular unit units.

\[ \vec{r}=x\hat{i}+y\hat{i}+z\hat{i} \]

Output :

Representation of a position with i, j, k

And the \hat command is used to place a hat symbol above each unit quantity.

Cross product

The cross product is denoted by a cross mark between two quantities. Its result is also an entity that is written in the form of a unit vector or matrix. And you need to use \times command to use the cross mark.

\[ \vec{p}\times \vec{q}=|\vec{p}|\vec{q}|sin\theta \hat{n} \]

Output :

Cross product notation

Notice that the symbol for theta is created using the \theta command.

Dot Product

You can use dot symbols for dot products in different ways. We will use the \cdot command for dot product.

\[ \vec{p}\cdot\vec{q}=|\vec{p}|\vec{q}|cos\theta \]

Output :

Dot product notation

Using Physics Package for Notation

The physics package is very useful for writing vectors and other physics-related symbols with ease.

It provides simple commands like \va and \vb for arrow and bold formats, respectively.

\documentclass{article}
\usepackage{physics}
\begin{document}
 \[ \va{a} \]
 \[ \va*{a} \]
 \[ \vb{a} \]
 \[ \vb*{a} \]
\end{document}

Output :

Vector notation using physics package

The package makes it easy to place an arrow over your expression and to simplify your code. You can also represent various operations using the following commands.

\documentclass{article}
\usepackage{physics}
\begin{document}
 \[ \vu*{a} \]
 \[ \va{p}\vdot\va{q} \]
 \[ \va{p}\cp\va{q} \]
 \[ \abs{\va*{a}} \]
\end{document}

Output :

Various operations demonstrated with the physics package

Share tutorial

2 thoughts on “How to write and format vectors in LaTeX?”

Leave a Comment

Your email address will not be published. Required fields are marked *