## Friday, August 5, 2011

### The align environment in LaTeX

Here is a little on some equation formatting in LaTex. I've posted some information on this before which might have been a little messy. It needs cleaning up, and I have used some of these commands now so I have some experience to write about them and post examples.

The eqnarray environment is outdated and no longer used or needed. The new environment align has replaced this environment with improvements. For more see this link here:

LaTeX Wiki - Align (environment) - http://latex.wikia.com/wiki/Align_(environment)

Here are some examples that I have written:

\begin{align*}
\textbf{u}_t &= \dfrac{\partial \textbf{u}}{\partial t} \\
\textbf{u} &= \text{vector of dependent variables} \\
t &= \text{initial value independent variable} \\
\textbf{x} & = \text{boundary value independent variables} \\
\textbf{f} &= \text{spatial differential operator} = \textbf{f} \left( \textbf{x}, t, \textbf{u}, \textbf{u}_x, \textbf{u}_{xx}, \ldots \right)
\end{align*}



\begin{align*}
\textbf{u}_t &= \dfrac{\partial \textbf{u}}{\partial t} \\
\textbf{u} &= \text{vector of dependent variables} \\
t &= \text{initial value independent variable} \\
\textbf{x} & = \text{boundary value independent variables} \\
\textbf{f} &= \text{spatial differential operator} = \textbf{f} \left( \textbf{x}, t, \textbf{u}, \textbf{u}_x, \textbf{u}_{xx}, \ldots \right)
\end{align*}

(Also aligned works to produce the same code in THIS post. I stumbled upon a great LaTeX code display method so i have to update some older posts since I couldn't get them to work):

\begin{aligned}
\textbf{u}_t &= \dfrac{\partial \textbf{u}}{\partial t} \\
\textbf{u} &= \text{vector of dependent variables} \\
t &= \text{initial value independent variable} \\
\textbf{x} & = \text{boundary value independent variables} \\
\textbf{f} &= \text{spatial differential operator} = \textbf{f} \left( \textbf{x}, t, \textbf{u}, \textbf{u}_x, \textbf{u}_{xx}, \ldots \right)
\end{aligned}

\begin{aligned}
\textbf{u}_t &= \dfrac{\partial \textbf{u}}{\partial t} \\
\textbf{u} &= \text{vector of dependent variables} \\
t &= \text{initial value independent variable} \\
\textbf{x} & = \text{boundary value independent variables} \\
\textbf{f} &= \text{spatial differential operator} = \textbf{f} \left( \textbf{x}, t, \textbf{u}, \textbf{u}_x, \textbf{u}_{xx}, \ldots \right)
\end{aligned}

Edit: Eeewww, I'm going to have to change that code display. It IS UGLY!! I need to tweak some things because my blockquote needs to change too. I want to put a box/frame or whatever around it so that it pops out at the reader and is distinguishable.

Edit 2: Ok, so I fixed up the blockquotes and code display (I think, I can't remember now it's been so long!! :P)

In order to have the equation number at the end of a long, multi-line equation use the command \nonumber right before you end the line with the double slashes

\begin{align}
\dfrac{\partial^2 T \left( x, t + \dfrac{\Delta t}{2} \right)}{\partial x^2} = &\dfrac{1}{2} \left[ \dfrac{T \left( x + \Delta x, t + \Delta t \right) - 2 T \left( x, t + \Delta t \right) + T \left( x - \Delta x, t + \Delta t \right)}{\Delta x^2} \right. \nonumber \\ &\left. + \dfrac{T \left( x + \Delta x, t \right) - 2 T \left( x, t \right) + T \left( x - \Delta x, t \right)}{\Delta x^2} \right]  + O \left( \Delta x^2 \right)
\end{align}

In order to center the equation number, surround the array environment with an equation environment


\begin{align}
\dfrac{\partial^2 T \left( x, t + \dfrac{\Delta t}{2} \right)}{\partial x^2} = &\dfrac{1}{2} \left[ \dfrac{T \left( x + \Delta x, t + \Delta t \right) - 2 T \left( x, t + \Delta t \right) + T \left( x - \Delta x, t + \Delta t \right)}{\Delta x^2} \right. \\ &\left. + \dfrac{T \left( x + \Delta x, t \right) - 2 T \left( x, t \right) + T \left( x - \Delta x, t \right)}{\Delta x^2} \right]  + O \left( \Delta x^2 \right)
\end{align}