eqnarray
and align
are both LaTeX environments used for displaying mathematical equations. However, there are significant differences between them in terms of usage and functionality.
eqnarray
- Alignment:
eqnarray
is primarily used for aligning multiple equations horizontally. It provides a way to align equations at specific points using&
. - No automatic numbering: Equations within
eqnarray
are not automatically numbered. If you want to label equations, you have to do it manually using\label{}
. - Limited spacing control:
eqnarray
has limited control over spacing between equations. This can sometimes lead to undesirable spacing in complex equations. - Not recommended: Due to its limitations and potential issues with spacing,
eqnarray
is generally not recommended for new documents. It has been superseded by more flexible environments likealign
.
align
- Alignment:
align
is a more versatile environment for aligning equations. It allows for aligning equations at multiple points using&
. This makes it suitable for a wider range of alignment needs. - Automatic numbering: Equations within
align
are automatically numbered unless suppressed with\nonumber
. This makes it convenient for referencing equations within the document. - Better spacing control:
align
provides better control over spacing between equations, leading to more consistent and visually appealing output. - Recommended:
align
is the recommended environment for aligning equations in modern LaTeX documents. It offers more flexibility, better spacing control, and automatic numbering compared toeqnarray
.
Example of eqnarray vs align
Here an example of using both eqnarray
and align
environments to display equations:
Using eqnarray:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Using \texttt{eqnarray}:
\begin{eqnarray}
2x + 3y &=& 7 \\
4x - 5y &=& 3
\end{eqnarray}
\end{document}
Using align:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Using \texttt{align}:
\begin{align}
2x + 3y &= 7 \\
4x - 5y &= 3
\end{align}
\end{document}
In both examples, we’re typesetting the same equations. When you compile the LaTeX code, you’ll notice that both display similar results, but the ‘align’ environment provides improved spacing and automatically numbers equations.
Summary:
- Use
eqnarray
if you need basic alignment of equations and don’t require automatic numbering or advanced spacing control. - Use
align
for more complex alignment needs, automatic equation numbering, and better spacing control. It is the preferred choice for most equation alignment tasks in latex documents.
Check our blog on: How to Use eqnarray in LaTeX: Multiline Equations