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 :
When you compile this, you will see a neat arrow over p.
\[ \vec{p}=m\vec{v} \]
Output :
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 :
To fix this, use the \overrightarrow
command, which adjusts the arrow length.
\[ \overrightarrow{AB} \]
Output :
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}
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 :
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 :
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 :
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 :
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 :
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 :
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 :
very interesting and useful
Nice Work!