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

  • LaTeX
  • Thread starter Eclair_de_XII
  • Start date
  • Tags
    Notes
In summary, the align environment from AMSLaTeX can be used to create a table with equations on one side and text on the other. The code for this would include the use of the align* environment and the \text{} command for adding text. Additionally, the xcolor package can be used to color rows, columns, and individual cells in the table. This can be done by using \rowcolor{}, >{\columncolor{}}, and \cellcolor{} commands respectively. It is also possible to define a new column type to make the code more concise.
  • #1
Eclair_de_XII
1,083
91
TL;DR 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?
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:
Physics news on Phys.org
  • #2
Have you tried a table? You could have one column for your equations and another for your comments.
 
  • #3
Huh, I had not thought it possible to make a table consisting of mathematical equations on one side and text on the other.
 
  • #4
Eclair_de_XII said:
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
Eclair_de_XII said:
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
Eclair_de_XII said:
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
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
DrClaude said:
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
I forgot to do something yesterday. I'm not sure if simply up-voting a post would convey a message of thanks properly.

Wrichik Basu said:
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.

Wrichik Basu said:
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

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

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

To add notes to the side of your equations, you can use the \tag{} command in LaTeX, or the \mathrlap{} command in MathJax. This will allow you to add text or symbols to the right or left side of your equations.

Can I add notes to specific parts of my equation?

Yes, you can add notes to specific parts of your equation by using the \underset{}{} command in LaTeX, or the \underscript{}{} command in MathJax. This will allow you to add text or symbols directly below or above a specific part of your equation.

How do I align my notes with my equations?

To align your notes with your equations, you can use the \tag*{} or \mathrlap*{} commands in LaTeX and MathJax respectively. These commands will align your notes with the equations, regardless of the length of the notes.

Can I add multiple notes to one equation?

Yes, you can add multiple notes to one equation by using the \tag{} command in combination with the \shortintertext{} command in LaTeX, or the \mathrlap{} command in combination with the \shortintertext{} command in MathJax. This will allow you to add multiple notes at different points in your equation.

How do I change the font or size of my notes?

You can change the font or size of your notes by using the \tagfont{} or \tagfontsize{} commands in LaTeX, or the \mathrlapfont{} or \mathrlapfontsize{} commands in MathJax. These commands will allow you to customize the appearance of your notes to match your preferences.

Similar threads

Replies
1
Views
1K
Replies
8
Views
2K
Replies
4
Views
2K
Replies
3
Views
1K
Replies
2
Views
750
Replies
2
Views
1K
Replies
6
Views
6K
Replies
4
Views
1K
Back
Top