Latex memo

Numbering equations in align environment

In align environment, all equations are numbered by default, use \nonumber to make equation on the same line not numbered.
Example:
Code:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
\frac{w^* +\delta V_u^1}{r + \delta} &= V_u^{0} \nonumber \\
w^* &= r V_u^1 - \frac{b(r + \delta)}{1 + r}
\end{align}
\end{document}
Result:

In align* environment, all equations are not numbered by default, how about we want to make one equation numbered? Is there any analog of \nonumber? From Ian Thompson at https://tex.stackexchange.com/questions/42726/align-but-show-one-equation-number-at-the-end, we can add the following command before the document begins:
\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}} % From Ian Thompson at https://tex.stackexchange.com/questions/42726/align-but-show-one-equation-number-at-the-end
Then, we can use \numberthis to make equation on the same line numbered in align* environment. Example:
Code:
\documentclass{article}
\usepackage{amsmath}
\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}} % From Ian Thompson at https://tex.stackexchange.com/questions/42726/align-but-show-one-equation-number-at-the-end
\begin{document}
\begin{align*}
\frac{w^* +\delta V_u^1}{r + \delta} &= V_u^{0} \\
w^* &= r V_u^1 - \frac{b(r + \delta)}{1 + r} \numberthis
\end{align*}
\end{document}
Result:
After numbering equations, we can use \label{[equation label]} to label them at the end of the equation like:
\documentclass{article}
\usepackage{amsmath}
\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}} % From Ian Thompson at https://tex.stackexchange.com/questions/42726/align-but-show-one-equation-number-at-the-end
\begin{document}
\begin{align*}
\frac{w^* +\delta V_u^1}{r + \delta} &= V_u^{0} \\
w^* &= r V_u^1 - \frac{b(r + \delta)}{1 + r} \label{reservation_wage} \numberthis
\end{align*}
\end{document}
Later, we can use \ref {[equation label]} to refer to that equation, where \ref {[equation label]} becomes the equation number in the document complied.

Commenting equations in align environment

Sometimes, we want to comment our equation like how to derive such equation. From Peter Grill at https://tex.stackexchange.com/questions/47687/adding-line-by-line-comments-to-math-proofs and Torbjørn T. at https://tex.stackexchange.com/questions/159723/what-does-a-double-ampersand-mean-in-latex, in align environment, we can use & (column separator) to divide one line into two parts for equation and comment respectively, just like tabular environment. Example:
Code:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\frac{w^* +\delta V_u^1}{r + \delta} &= V_u^{0} && \text{From (4)} \\
\frac{w^* +\delta V_u^1}{r + \delta} &= V_u^{1} - \frac{b}{1+r} && \text{From (2) and (3), } V_u^1 = \frac{b}{1+r} + V_u^0 \\
w^* &= r V_u^1 - \frac{b(r + \delta)}{1 + r}
\end{align*}
\end{document}
Result:
Note that we follow Peter Grill, using && instead of usual & to separate the two parts. The reason is given by Torbjørn T. - in align environment, the alignments of columns are right, left, right, left, right, left, ... In the example, we actually have four columns in each line of equations - first column is before =, second column is between = and before &&, third column is empty and fourth column is after && such that the fourth column is left aligned. Also, as there are some space between each pair of right-left columns, we can separate equation and comment into two parts using &&.

Explaining each part of equations

We can explain each part of equations with \underbrace. Example:
Code:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\frac{\partial u^*}{\partial b} &= \underbrace{\frac{\partial u^*}{\partial w^*}}_{> 0 \text{ as $F(w^*)$ is increasing in $w^*$}} \times \underbrace{\frac{\partial w^*}{\partial b}}_{< 0 \text{ from (\ref{dwdb})}} < 0
\end{align*}
\end{document}
Result:

Cases in equations

Use cases environment to differentiate different cases for equations. Example:
Code:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
 \frac{\partial w^*_{\delta}}{\partial b} &= \frac{r(r+\delta) + \pi_2 F(w^*_{\delta})\frac{\partial w^*_{\delta}}{\partial b}}{(r + \delta)(r + \pi_2) - \pi_2 \delta} \\
 \frac{\partial w^*_{\delta}}{\partial b} &= \frac{r(r + \delta)}{r(r+\delta) + \pi_2[r - F(w^*_{\delta})]} 
 \begin{cases}
 > 0\text{ if } r(r+\delta) + \pi_2[r - F(w^*_{\delta})] > 0\\
 < 0\text{ if } r(r+\delta) + \pi_2[r - F(w^*_{\delta})] < 0\\
 \end{cases} \\
 \frac{\partial u_{\gamma}^{*}}{\partial b} &= \underbrace{\frac{\partial u_{\gamma}^{*}}{\partial w^*_{\delta}}}_{> 0}\frac{\partial w^*_{\delta}}{\partial b}
 \begin{cases}
 > 0\text{ if } r(r+\delta) + \pi_2[r - F(w^*_{\delta})] > 0\\
 < 0\text{ if } r(r+\delta) + \pi_2[r - F(w^*_{\delta})] < 0\\
 \end{cases}
\end{align*}
\end{document}
Result:

Colored text

Use package color with command \color. Example:
Code:
\documentclass{article}
\usepackage{color}
\begin{document}
Coming up: Crazy example \\
\color{red} Red: Red is the best! \\
\color{blue} Blue: What are you saying? Blue is the best! \\
\color{red} Red: Green, who is the best? \color{blue} Blue: Green, I know you will say I am the best, right? \\
\color{green} Green: Does it matter who is the best? Everyone here is just a color, just three values of RGB. Changing enough values of RGB, we can be each other! Therefore, we are the best! \\
\color{red} Red, \color{green} Green, \color{blue} Blue: \color{red} Yeah! Color is the best! \color{green} Long live the color! \color{blue} Color for the win! \\
\color{black} Note that apart from predefined color, we can also \color[rgb]{0.3,0.8,0.9} color text in rgb.
\end{document}
Result:
By the way, my favorite color is green.

Comments

Popular posts from this blog

Linux memo

Stability of steady-state equilibrium for overlapping generation model