# How do I add notes to the side of my equations?

## Summary:

Let's say I wanted to write out a calculation that required some steps that I wanted to write out on the right-side of each equation in an align environment. How would I accomplish this?

## Main Question or Discussion Point

Let's say I wanted to describe the first step of this calculation by writing "Factor out ##c_2c_3,c_3,c_3## from these determinant expansions." on the right side of the second expression on the right. Which environment would work well?

Below is the code generating the text in the image above.

Code:
\documentclass{article}

\usepackage{mathtools}

\newcommand{\sn}[1]{s_#1}
\newcommand{\cs}[1]{c_#1}

\begin{document}

\begin{align*}
r^{-3}\det[c'] &=&% First line.
-\sn{3} \det
\begin{pmatrix}
-\sn{1} \cs{2} \cs{3} & -\cs{1} \sn{2} \cs{3} & -\cs{1} \cs{2} \sn{3} \\
\cs{1} \cs{2} \cs{3} & -\sn{1} \sn{2} \cs{3} & -\sn{1} \cs{2} \sn{3} \\
0 & \cs{2} \cs{3} & -\sn{2} \sn{3}
\end{pmatrix}
\\[6pt]&+&
\cs{3} \det
\begin{pmatrix}
\cs{1} \cs{2} \cs{3} & -\sn{1} \cs{2} \cs{3} & -\cs{1} \sn{2} \cs{3} \\
\sn{1} \cs{2} \cs{3} & \cs{1} \cs{2} \cs{3} & -\sn{1} \sn{2} \cs{3} \\
\sn{2} \cs{3} & 0 & \cs{2} \cs{3}
\end{pmatrix}\\[6pt]&=&% Second line.
\cs{2} \sn{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1}  & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1}  & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&+&
\cs{2} \cs{3}^4 \det
\begin{pmatrix}
\cs{1} \cs{2} & -\sn{1} & -\cs{1} \sn{2} \\
\sn{1} \cs{2} & \cs{1} & -\sn{1} \sn{2} \\
\sn{2} & 0 & \cs{2}
\end{pmatrix}\\[6pt]&=&% Third line.
\cs{2} \sn{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1}  & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1}  & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&+&
\cs{2} \cs{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1}  & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1}  & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&=&% Fourth line.
\cs{2} \cs{3}^2 \det
\begin{pmatrix}
-\sn{1}  & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1}  & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}
\end{align*}

\end{document}
Also, I want to color some of these columns. I found an article relating to this, but I am most confused about the syntax, and how to implement it into my code.

https://tex.stackexchange.com/questions/69713/matrix-change-row-or-column-background

Last edited:

Related MATLAB, Maple, Mathematica, LaTeX News on Phys.org
FactChecker
Gold Member
Have you tried a table? You could have one column for your equations and another for your comments.

Huh, I had not thought it possible to make a table consisting of mathematical equations on one side and text on the other.

Wrichik Basu
Gold Member
Let's say I wanted to describe the first step of this calculation by writing "Factor out c2c3,c3,c3c2c3,c3,c3c_2c_3,c_3,c_3 from these determinant expansions." on the right side of the second expression on the right. Which environment would work well?
Before ending a line with \\, you have to append
&& \text{Factor out } \cs{2}\cs{3}, \ \cs{3}, \ \cs{3} \ \text{from these determinant expansions}. Your new code would look like this:
Code:
\documentclass{article}

\usepackage{mathtools}

\newcommand{\sn}[1]{s_#1}
\newcommand{\cs}[1]{c_#1}

\begin{document}

\begin{align*}
r^{-3}\det[c'] &=&% First line.
-\sn{3} \det
\begin{pmatrix}
-\sn{1} \cs{2} \cs{3} & -\cs{1} \sn{2} \cs{3} & -\cs{1} \cs{2} \sn{3} \\
\cs{1} \cs{2} \cs{3} & -\sn{1} \sn{2} \cs{3} & -\sn{1} \cs{2} \sn{3} \\
0 & \cs{2} \cs{3} & -\sn{2} \sn{3}
\end{pmatrix}
\\[6pt]&+&
\cs{3} \det
\begin{pmatrix}
\cs{1} \cs{2} \cs{3} & -\sn{1} \cs{2} \cs{3} & -\cs{1} \sn{2} \cs{3} \\
\sn{1} \cs{2} \cs{3} & \cs{1} \cs{2} \cs{3} & -\sn{1} \sn{2} \cs{3} \\
\sn{2} \cs{3} & 0 & \cs{2} \cs{3}
\end{pmatrix} && \text{Factor out } \cs{2}\cs{3}, \ \cs{3}, \ \cs{3} \ \text{from these determinant expansions}
\\[6pt]&=&% Second line.
\cs{2} \sn{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1}  & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1}  & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&+&
\cs{2} \cs{3}^4 \det
\begin{pmatrix}
\cs{1} \cs{2} & -\sn{1} & -\cs{1} \sn{2} \\
\sn{1} \cs{2} & \cs{1} & -\sn{1} \sn{2} \\
\sn{2} & 0 & \cs{2}
\end{pmatrix}\\[6pt]&=&% Third line.
\cs{2} \sn{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1}  & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1}  & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&+&
\cs{2} \cs{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1}  & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1}  & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&=&% Fourth line.
\cs{2} \cs{3}^2 \det
\begin{pmatrix}
-\sn{1}  & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1}  & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}
\end{align*}

\end{document}
(Hope that I placed it at the correct position.)

Note that if you include long comments to equations, you will have to change your page margins. Otherwise, the text will go out of page. Better keep the comments short and simple.

Also have a look at the following:
https://tex.stackexchange.com/questions/147592/to-have-nice-tabbed-text-next-to-equations

Edit: Corrected typo.

Last edited:
Eclair_de_XII
Wrichik Basu
Gold Member
Also, I want to color some of these columns.
This can be done in pmatrix environment, but it doesn't look impressive. The row color overlaps with the brackets:

If you use the array environment, it looks better:

You need to import the xcolor package.

The code would look something like this:
Using color in table row and column:
\documentclass{article}
\usepackage{mathtools}
\usepackage[table]{xcolor}

\newcommand{\sn}[1]{s_#1}
\newcommand{\cs}[1]{c_#1}
\newcolumntype{a}{>{\columncolor{red}}c}

\begin{document}

\begin{align*}
r^{-3}\det[c'] &=
-\sn{3} \det
\left(\begin{array}{ccc}
\rowcolor{red!20}
-\sn{1} \cs{2} \cs{3} & -\cs{1} \sn{2} \cs{3} & -\cs{1} \cs{2} \sn{3} \\
\cs{1} \cs{2} \cs{3} & \cellcolor{green!30} -\sn{1} \sn{2} \cs{3} & -\sn{1} \cs{2} \sn{3} \\
\rowcolor{yellow!50}
0 & \cs{2} \cs{3} & -\sn{2} \sn{3}
\end{array}\right)\\
&= 3\\
&= \cs{2} \sn{3}^2 \cs{3}^2 \ \det
\left(\begin{array}{>{\columncolor{blue!30}}cca}
-\sn{1}  & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1}  & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{array}\right)
\end{align*}

\end{document}
The above code would generate:

To summarise, if you place \rowcolor{red!20} before a row, that row will get coloured. If you want to colour a column, place >{\columncolor{blue!30}} before the column letter in the declaration of array. If you want to colour only a cell, use \cellcolor{green!10} at the beginning of the cell. You can also define a new column type so as to avoid clutter.

See the highlighted lines in the above code.

Feel free to ask questions if anything is not clear.

Last edited:
Eclair_de_XII
FactChecker
Gold Member
Huh, I had not thought it possible to make a table consisting of mathematical equations on one side and text on the other.
You might be right. I've never tried it.

DrClaude
Mentor
You can use the align environment from AMSLaTeX

\begin{align*} E &= mc^2 & \text{Einstein} \\ i \hbar \frac{\partial}{\partial t} \psi &= \hat{H} \psi & \text{Schrödinger} \end{align*}

Code:
\begin{align*}
E &= mc^2  & \text{Einstein} \\
i \hbar \frac{\partial}{\partial t} \psi &= \hat{H} \psi & \text{Schrödinger}
\end{align*}
By the way, I don't understand why you define \sn and \cs. It takes fewer keystrokes to type c_1 than \cs{1}.

By the way, I don't understand why you define \sn and \cs. It takes fewer keystrokes to type c_1 than \cs{1}.
I see your point; the latter string would take twice as many keystrokes to type as the former, depending on if holding the shift key can be counted as a keystroke. I guess I just got too caught up in writing macros that I had neglected to consider the fact that they're ideally used in order to save time and keystrokes.

I forgot to do something yesterday. I'm not sure if simply up-voting a post would convey a message of thanks properly.

Before ending a line with \\, you have to append
&& \text{Factor out } \cs{2}\cs{3}, \ \cs{3}, \ \cs{3} \ \text{from these determinant expansions}.
Thank you for the information as well as the links. I shall keep them on hand should I decide to write amateur textbook-style explanations again.

To summarise, if you place \rowcolor{red!20} before a row, that row will get coloured. If you want to colour a column, place >{\columncolor{blue!30}} before the column letter in the declaration of array. If you want to colour only a cell, use \cellcolor{green!10} at the beginning of the cell. You can also define a new column type so as to avoid clutter.
Thank you for the clarification. I am grateful for someone translating LaTeX for me. It's much more satisfying learning the syntax and the like, rather than searching for similar code on the world-wide web and copy-pasting it into my own document.

Wrichik Basu