Posted: Jun 27, 2015 8:06 pm
Pulsar's Latex Tutorial Part 4 - reboot

Pulsar wrote:

Code: Select all
$\textbf{A }\mathbf{\LaTeX\ }\textbf{Tutorial, part 4}$ Equations

I've used the \begin{align} \end{align} environment several times already, without discussing its use: with align, you can type multiple, aligned equations. The ampersand & serves as a tab stop; usually, you want the lines to be aligned on the equation sign:

Code: Select all
\begin{align}\binom{5}{3} &= \frac{5!}{2!\; 3!}\\&= \frac{5\cdot 4 \cdot 3 \cdot 2}{3 \cdot 2 \cdot 2}\\&= 10\end{align} You can also align two sets of equation side by side, as follows:

Code: Select all
\begin{align}y & =d & z & =1\\y & =cx+d & z & =x+1 \end{align} If you want even more, use the alignat environment. It has a parameter denoting the amount of aligned columns. Here's an example with three:

Code: Select all
\begin{alignat}{3}i_{11} & =0.25 & i_{12} & =i_{21} & i_{13} & =i_{23}\\i_{21} & =-i_{11} & i_{22} & =0.5\,i_{12}& i_{23} & =i_{31}\\i_{31} & =0.33\,i_{22}\qquad & i_{32} & =0.15\,i_{32}\qquad & i_{33} & =i_{11}\end{alignat} Alternatively, you can centre equations rather than align them. To do this, use the gather environment.

NOTE: I couldn't get the original code to generate an image.

Original code:

Code: Select all
$\begin{gather}\displaystyle{\Gamma(x) = \int_0^{+\infty} t^{x-1} \, \text{e}^{-t} \, \text{d}t\\B(x,y) = \int_0^1 t^{x-1}\,(1-t)^{y-1}\,\text{d}t} \end{gather}$

So I switched the way the gather and displaystyle were nested with respect to one another.

Code: Select all
\begin{gather}\displaystyle{\Gamma(x) = \int_0^{+\infty} t^{x-1} \, \text{e}^{-t} \, \text{d}t\\B(x,y) = \int_0^1 t^{x-1}\,(1-t)^{y-1}\,\text{d}t} \end{gather} Long equations can be split with the multline environment. In the example below, you see that the \left( bracket has to be followed by a \right. (an invisible right bracket) at the end of the first line, otherwise Latex will raise an error. Likewise, the second line starts with \left. (an invisible left bracket) and ends with \right).

However, to ensure that the closing \right) is as big as the opening \left( , we need another trick: the command \vphantom{} inserts an invisible vertical space, given by the text inside the brackets - analogous to the horizontal \phantom{}. On the first line, the summation \sum_{i<j} is the largest symbol, so \vphantom{\sum_{i<j}} inserts an equally large, but invisible symbol on the second line, which guarantees that \left( and \right) are of the same size.

I had a similar problem with the original code.

Code: Select all
$\displaystyle{\begin{multline}\frac{1}{2}\Delta(f_{ij}f^{ij}) = 2\left( \sum_{i<j}\chi_{ij}(\sigma_{i} -\sigma_{j})^{2} + f^{ij}\nabla_{j}\nabla_{i} (\Delta f) + \right.\\\left. + \nabla_{k}f_{ij}\nabla^{k}f^{ij} + f^{ij}f^{k}\left[2\nabla_{i}R_{jk} -\nabla_{k}R_{ij}\right] \vphantom{\sum_{i<j}}\right)\end{multline}}$

So I reversed the nesting order of multline and displaystyle

Code: Select all
$\begin{multline}\displaystyle{\frac{1}{2}\Delta(f_{ij}f^{ij}) = 2\left( \sum_{i<j}\chi_{ij}(\sigma_{i} -\sigma_{j})^{2} + f^{ij}\nabla_{j}\nabla_{i} (\Delta f) + \right.\\\left. + \nabla_{k}f_{ij}\nabla^{k}f^{ij} + f^{ij}f^{k}\left[2\nabla_{i}R_{jk} -\nabla_{k}R_{ij}\right] \vphantom{\sum_{i<j}}\right)}\end{multline}$ 