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

  • #1
824
44

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?

Untitled.png
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:

Answers and Replies

  • #2
FactChecker
Science Advisor
Gold Member
5,591
2,073
Have you tried a table? You could have one column for your equations and another for your comments.
 
  • #3
824
44
Huh, I had not thought it possible to make a table consisting of mathematical equations on one side and text on the other.
 
  • #4
1,430
1,270
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

https://tex.stackexchange.com/questions/47687/adding-line-by-line-comments-to-math-proofs

Edit: Corrected typo.
 
Last edited:
  • Like
Likes Eclair_de_XII
  • #5
1,430
1,270
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:

1587711108074.png


If you use the array environment, it looks better:

1587711148075.png


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:

1587714142798.png


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:
  • Like
Likes Eclair_de_XII
  • #6
FactChecker
Science Advisor
Gold Member
5,591
2,073
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.
 
  • #7
DrClaude
Mentor
7,339
3,521
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}.
 
  • #8
824
44
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.
 
  • #9
824
44
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.
 
  • Like
Likes Wrichik Basu

Related Threads on How do I add notes to the side of my equations?

Replies
1
Views
4K
  • Last Post
Replies
4
Views
2K
Replies
1
Views
2K
Replies
1
Views
11K
Replies
3
Views
5K
Replies
3
Views
795
Replies
5
Views
10K
  • Last Post
Replies
2
Views
624
Top