11.2 Display and alignment structures for equations
The amsmath package defines several environments for creating displayed mathematics. These cover single- and multiple-line displays with single or multiple alignment points and various options for numbering equations within displays.
Throughout this section the term “equation” is used in a very particular way: to refer to a logically distinct part of a mathematical display that is frequently numbered for reference purposes and is also labeled (commonly by its number in parentheses). Such labels are often called tags.
11.2.1 Comparison of amsmath - mathtools with standard LATEX
Some of the multiple-line display environments allow you to align parts of the formula. In contrast to the original LaTEX environments eqnarray and eqnarray*, the structures implemented by the amsmath package use a slightly different and more straightforward method for marking the alignment points. Standard LaTEX’s
eqnarray* is similar to an array environment with {rcl} as the preamble and, therefore, requires two ampersand characters indicating the two alignment points. In the equivalent amsmath structures there is only a single alignment point (similar to a {rl} preamble), so only a single ampersand character should be used, placed to the left of the symbol (usually a relation) that should be aligned.
The amsmath structures give fixed spacing at the alignment points, whereas the eqnarray environment produces extra space depending on the parameter settings for array. The difference can be seen clearly in the next example, where the same equation is typeset using the equation, align, and eqnarray environments; the spaces in the eqnarray environment come out too wide for conventional standards of mathematical typesetting.
As in standard LaTEX, lines in an amsmath display are marked with \ (or the end of the environment). Because line breaking in a mathematical display usually requires a thorough understanding of the structure of the formula, it is commonly considered to be beyond today’s software capabilities. However, one of the last bigger projects undertaken by Michael Downes (1958–2003) precisely tackled this problem; it resulted in the breqn package (see Section 11.2.12 on page 146 for an overview).
Unlike eqnarray, the amsmath environments do not, by default, allow page breaks between lines (see Section 11.2.11). Furthermore, they move the equation tag out of the way if it would otherwise overprint the formula.
Another difference concerns the use of \[dimension] or \* within mathematical display environments. With amsmath, there must be no space between the \ and the or the *; otherwise, the optional argument or star will not be recognized. The reason is that brackets and stars are very common in mathematical formulas, so this restriction avoids the annoyance of having a genuine bracket belonging to the formula be mistaken for the start of the optional argument.
11.2.2 single equation on one line
The equation environment produces a single equation with an automatically generated number or tag placed on the extreme left or right according to the option in use (see Section 11.2.13); equation* does the same but omits a tag.
Note that the presence of the tag does not affect the positioning of the contents. If there is not enough room for it on the one line, the tag is shifted up or down: to the previous line when equation numbers are on the left, and to the next line when numbers are on the right.
11.2.3 A single equation on several lines - no alignment
The multline environment is a variation of the equation environment used only for equations that do not fit on a single line. In this environment \ must be used to mark the line breaks, because they are not found automatically.
The first line of a multline is aligned on an indentation from the left margin and the last line on the same indentation from the right margin.1 The size of this indentation is the value of the length ; thus, it can be changed using LaTEX’s and commands.
If a multline contains more than two lines, each line other than the first and last is centered individually within the display width (unless the option fleqn is used). It is, however, possible to force a single line to the left or the right by adding either or within that line.
A multline environment is a single (logical) equation and thus has only a single tag, the multline* having none; thus, none of the individual lines can be changed by the use of or . The tag, if present, is placed flush right on the last line with the default reqno option or flush left on the first line when the leqno option is used.
11.2.4 A single equation on several lines - with alignment
When a simple alignment is needed within a single multiple-line equation, the split environment is almost always the best choice. It uses a single ampersand (&) on each line to mark the alignment point.
Because it is always used as the content of a single (logical) equation, a split does not itself produce any numbering tag, and hence there is no starred variant. If needed, the outer display environment provides any needed tags.
Apart from commands such as or that produce no visible material, a split structure should normally constitute the entire body of the equation being split. It can consist of either a whole equation or equation* environment or one whole line of a gather or gather* environment; see Section 11.2.5.
When the centertags option is in effect (the default), the tag (and any other material in the equation outside the split) is centered vertically on the total height of the material from the split environment. When the tbtags option is specified, the tag is aligned with the last line of the split when the tag is on the right, and with the first line of the split when the tag is on the left.
In the next example the command is used to adjust the horizontal positioning. It is first used in the preamble to define an “invisible relation symbol” of width equal to that of its argument (in this case, =). Within the example it is used to align certain lines by starting them with a “phantom or invisible subformula” (see Section 11.7.2 on page 197).
11.2.5 Equation groups without alignment
The gather environment is used to put two or more equations into a single display without alignment between the equations. Each equation is separately centered within the display width and has its individual number tag, if needed. Each line of a gather is a single (logical) equation.
11.2.6 Equation groups with simple alignment
The align environment should be used for two or more equations in a single display with vertical alignment. The simplest form uses a single ampersand (&) on each line to mark the alignment point (usually just before a Relation symbol).
11.2.7 Multiple alignments - align, flalign, and alignat
An align environment can include more than one alignment point. The layout contains as many column-pairs as necessary and is similar to an array with a preamble of the form {rlrl…} except that it does not change the spacing around the alignment points. If it consists of n such rl column-pairs, then the number of ampersands per line is 2n - 1: one ampersand for alignment within each column-pair giving n; and n - 1 ampersands to separate the column-pairs.
Within the align environment, the material is spread out evenly across the display width. All extra (or white) space within the line is distributed equally “between consecutive rl column-pairs” and the two display margins.
11.2.8 Display environments as mini-pages
All the environments described so far produce material set to the full display width. A few of these environments have also been adapted to provide self-contained alignment structures, as if they were set as the only content of a minipage environment whose size, in both directions, is determined by its contents. You can think of them as subsidiary environments that can be used within any of the display environments discussed so far. (Below we use them inside equation.)
The environment names are changed only slightly— to aligned, gathered, and alignedat — and when using mathtools, there are additionally lgathered, rgathered, and multlined. Note that an aligned environment avoids unnecessary space on the left and right; thus, it mostly resembles the flalign environment.
Like minipage, these environments take an optional argument that specifies the vertical positioning with respect to the material on either side. The default alignment of the box is centered ([c]). Of course, like split, they are used only within equations, and they never produce tags.
11.2.9 Interrupting displays with short text
The command is used for a short passage of text (typically at most a few lines) that appears between the lines of a display alignment. Its importance stems from the fact that all the alignment properties are unaffected by the text, which itself is typeset as a normal paragraph set to the display width; this alignment would not be possible if you simply ended the display and then started a new display after the text. This command may appear only immediately after a \ or \* command.
Here the words “and finally” are outside the alignment, at the left margin, but all three equations are aligned.
11.2.10 Vertical space in and around displays
As is usual in LaTEX, the optional argument \[dimension] gives extra vertical space between two lines in all amsmath display environments (there must be no space between the \ and the character delimiting the optional argument). The vertical spaces before and after each display environment are controlled by the following rubber lengths, where the values in parentheses are those for with the (default) 10pt option in the standard LaTEX classes1:
11.2.11 Page breaks in and around displays
Automatic page breaking before and after each display environment is controlled by the penalty parameters (for breaking before a display; default 10000, i.e., no break allowed) and (for breaking after a display, default 0; i.e., break allowed). The defaults are already set in standard LaTEX and are not changed by amsmath.
Unlike standard LaTEX, the amsmath display environments do not, by default, allow page breaks between lines of the display. The reason for this behavior is that correct page breaks in such locations depend heavily on the structure of the display, so they often require individual attention from the author.
With amsmath such individual control of page breaks is best achieved via the command, but it should be used only when absolutely necessary to allow a page break within a display. The command must go before the \, at which a break may be taken, and it applies only to that line and can be used only within an environment that produces a complete display. Somewhat like standard LaTEX’s (see Section 6.2.2 in [106]), takes an optional integer as its argument, with a value ranging from zero to four, denoting the desirability of the page break: means “it is permissible to break here” without encouraging a break; with no optional argument is the same as and forces a break. This command cannot be used to discourage or prevent page breaks. Note that it makes no sense to break within a “mini-page display”, as those environments should never be split over two pages.
This kind of adjustment is fine-tuning, like the insertion of line breaks and page breaks in text. It should therefore be left until your document is nearly finalized. Otherwise, you may end up redoing the fine-tuning several times to keep up with changing document content.
The command , which obeys the usual LaTEX scoping rules, is equivalent to putting before every line end in any display environment within its scope; i.e., it allows page breaks anywhere in the math displays. The command can take an optional argument for finer control: [1] means allow page breaks but avoid them as far as possible, while [2] to [4] allow breaks with increasing permissiveness. Within the scope of an command, the \* command can be used to prohibit a page break and individual commands override both the default and the effect of an .
11.2.12 breqn — Automatic line breaking in math displays
Shortly before his early death, Michael Downes (1958–2003) started to develop a sophisticated package for automatic line breaking in display math equations. Morten Høgholm adopted this code and made it available to the general public. These days it is maintained by him and Will Robertson.
The dmath environment corresponds to the equation environment with the difference that it automatically breaks the formula into different lines if necessary and aligns them at relation symbols or binary symbols (but then indented). There also exists a dmath* version that omits the equation number, i.e., it corresponds to amsmath’s equation* environment. With the help of the optional key/value list, several aspects of the display can be adjusted.
As a teaser we repeat Example 11-2-9 from page 136 but now use dmath instead of split. As you can see, the source gets much simpler now (relatively speaking), because we do not have to define alignment points, line breaks, extra , etc., to get the formula adequately broken across several lines. All that is done automatically behind the scenes by the package.
If you compare the output of the two examples, you see that they are almost identical. The most noticeable difference is the move of the + from the end of the second line to the third, but this is arguably even better than our manual layout in Example 11-2-9.
11.2.14 Fine-tuning tag placement
Optimal placement of equation number tags can be a rather complex problem in multiple-line displays. These display environments try hard to avoid overprinting an equation number on the equation contents; if necessary, the number tag is moved down or up, onto a separate line. The difficulty of accurately determining the layout of a display can occasionally result in a tag placement that needs further adjustment. Here is an example of the kind of thing that can happen and a strategy for fixing it. The automatic tag placement is clearly not very good.
11.2.15 Subordinate numbering sequences
The amsmath package provides a subequations environment to support “equation subnumbering” with tags of the form (2a), (2b), (2c), and so on. All the tagged equations within it use this subnumbering scheme based on two normal LaTEX counters: parentequation and equation.
The next example demonstrates that the tag can be redefined to some extent, but note that the redefinition for must appear within the subequations environment! (Appendix A.2.1 discusses counter manipulations.)
11.2.16 Resetting the equation counter
It is a fairly common practice to have equations numbered within sections or chapters, using tags such as (1.1), (1.2), . . . , (2.1), (2.2), . . . . These days this can be easily set up with standard LaTEX by using the declaration .
For example, to get compound equation tags including the section number, with the equation counter being automatically reset for each section, put this declaration in the preamble: .
Sometimes such a setup is already done by the document class you use, e.g., the report or book classes of standard LaTEX number equations per chapter. If you would like to undo such a setting, use .