Sunday, May 17, 2009

Tabular Row Spacing

We've already covered how to deal with the row height in latex, but what if you want to make only certain rows separated. When designing a table with multiple lines per cell we will use the \hline structure to make the table seem like it has multiple rows.


In this case we need to separate the rows individually, which can be done at the end of the tabular line. Consider the following code:

\begin{tabular}{rl}
{\bf First Column} & {\bf Second Column} \\\hline \\ [-1.5ex]
First Item & First Attribute \\
& Second Attribute \\
& Third Attribute \\ [1ex] \hline \\ [-1.5ex]
Second Item & First Attribute \\
& Second Attribute \\
& Third Attribute \\
& Fourth Attribute \\ [1ex] \hline \\ [-1.5ex]
Third Item & First Attribute \\
& Second Attribute \\ [1ex] \hline \\ [-1.5ex]
Fourth Item & First Attribute \\
& Second Attribute \\
& Third Attribute \\ [1ex] \hline \\ [-1.5ex]
\end{tabular}

Putting [1ex] at the end of a line creates that much extra space after the line. The idea here is to make 1ex before the \hline, and then put a completely blank line after it. the [-1.5ex] moves the line after the \hline up, making the gap less than a full line. The result is in the following image:

Making Multiline Equations

Just a quick post, as this is something that I've had to do (yet again), so I thought I'd write it down. When you need an equation with multiple lines, say when you're decomposing an equation through several steps, the procedure you should use is eqnarray:

Equation array: eqnarray
usage: \begin{eqnarray} ... \end{eqnarray}

The usage of eqnarray is fairly straight-forward: an equation array is a standard array with three columns formatted to the right, center and to the left {rcl}. The idea is that the left side of the equation is the first statement, the middle column is the = sign and the right column is the derivation. It differs from a standard array in that it is in the formula environment (within the $ environment) so it can take standard mathematical notation. The following example produces a two-line equation:

\begin{eqnarray*}
\Delta D(s,N) & = & D_N(\hat{\mu};,y) - D_{N_L,N_R}(\hat{\mu}_L,\hat{\mu}_R;y)\\
& = & \sum_{i=1}^n D(\hat{\mu};y_i) - \left[\sum_{i=1}^{n_L} D(\hat{\mu};y_i)+\sum_{i=1}^{n_R} D(\hat{\mu};y_i)\right]\\
\end{eqnarray*}

This produces the following equation: