Equation Numbering Pitfalls Of Eqnarray And How To Avoid Them

Troubles with eqnarray

The eqnarray environment has been used extensively for typing multi-line mathematical equations in LaTeX documents. However, it has several drawbacks when it comes to inconsistent spacing around equations, poor breaking behavior across lines, and limited control over equation numbering.

Inconsistent Spacing Around Equations

A common issue with the eqnarray environment is the inconsistent spacing it introduces around equations. The lines of multi-line equations are separated by \\, which adds vertical space. This causes the spacing to be different above and below lines of the same eqnarray mathematical block.

For example, there may be extra space below the first line before the second line. This inconsistent spacing looks unprofessional in formal documents where uniformity is expected.

Poor Equation Breaking Behavior

Another problem with eqnarray is its poor behavior when breaking equations across multiple lines. LaTeX's algorithm for choosing line breaks can sometimes place breaks at awkward or unsuitable points in long equations.

This may result in individual lines being too short or too long, or break points that disrupt the logical flow of the math. This causes equations to look disjointed and be harder to read, negatively impacting the reader's understanding.

Issues with Equation Numbering

Eqnarray's syntax of \\ for dividing equations into lines also complicates numbering multi-line equations. It does not provide a native way to control which lines get numbered or to customize the numbers themselves.

By default, eqnarray will number each line separately instead of treating multi-line equations as a unit. This causes issues when trying to reference equations and is again detrimental to mathematical readability.

Migrating to align

To overcome the spacing, breaking, and numbering issues with eqnarray, the recommended approach is to migrate to using the align environment for typed multi-line mathematics.

The align Environment for Better Spacing Control

The align environment, provided by the amsmath package, addresses the inconsistencies of eqnarray by introducing a framework with much better spacing control between lines.

Align separates lines not with \\ but the & symbol. This ensures uniform spacing above and below each line in a multi-line mathematical block.

Example align Code:

\begin{align} 
a &= b+c \\
d+e &= f  
\end{align}

By using align instead of eqnarray, the uneven spacing issues are eliminated right from the start, greatly improving equation readability.

Multi-line Equations with Alignment

Another major advantage of the align environment is the ability to align elements across multiple lines, as seen by the = symbols above. This alignment of mathematical terms again enhances visual structure and readability.

Eqnarray lacks native support for any sort of alignment. The align environment thus provides a clearer way of typing aesthetically pleasing multi-line equation layouts with alignment.

Numbering Equations Your Way

Align also enables full control over the numbering of multi-line equations through the use of tags.

Tagging Equations for Flexible Numbering

Each line in align can be labeled with a \tag command, which assigns a tag to the line that can then be referenced elsewhere. This helps treat the equation as a single entity.

Example Code Using \tag:

    \begin{align} 
    x &= y^2 \tag{1}\\
    a+b &= c \tag{2}  
    \end{align}

Now multi-line equations can be referred to by their unified tags, like Equation 1 and Equation 2 above. The tags overcome eqnarray's limitation of separately numbering each line.

Referencing Tagged Equations

These custom tags can then be referenced in text using the \eqref command. For example, "As seen in \eqref{2} ..." would link back to the full multi-line Equation 2.

Being able to fully control numbering and refer back to multi-line mathematical blocks greatly enhances document quality and coherence when typesetting mathematics-heavy papers or theses.

Avoiding Common Pitfalls

When transitioning from eqnarray to align, there are some key differences to note that can cause issues if overlooked.

Spacing Around Align vs. Spacing in eqnarray

As discussed earlier, align introduces consistent, uniform spacing between lines in a mathematical block. However, sometimes extra space is needed around align environments when embedded in paragraphs.

Eqnarray essentially prohibits any spacing around it without manual intervention. So be mindful that some vertical spacing adjustments may be required around align blocks.

Troubleshooting Equation Breaking Issues

Align also offers smarter automatic line breaking algorithms. However, manual override is still sometimes needed via the \\ break command to correct awkward breaks.

Tune line break points case-by-case if equations appear disjointed or uneven when typeset. Align gives control over the process to fix such issues as needed.

Handling Equation Numbers and References

Since align's \tag syntax affects numbering and references, it can interfere with the automatic numbering from the equations counter. Handle numbering carefully based on whether manual or automatic numbering is preferred.

Also double check that all \eqref links correctly point to the intended numbered equations. With full control comes full responsibility to get references right!

Leave a Reply

Your email address will not be published. Required fields are marked *